Skip to content

Commit 89518f4

Browse files
committedOct 1, 2015
[welcome page] fix font size on HiDPI display and improve disabled item style
1 parent 401f43c commit 89518f4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed
 

‎src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,33 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
4444
{
4545
color = QColor( 255, 255, 255, 60 );
4646
ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::HighlightedText ) );
47+
48+
QStyle *style = QApplication::style();
49+
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
4750
}
4851
else if ( option.state & QStyle::State_Enabled )
4952
{
5053
color = QColor( 100, 100, 100, 30 );
5154
ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Active, QPalette::Text ) );
55+
56+
QStyle *style = QApplication::style();
57+
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
5258
}
5359
else
5460
{
5561
color = QColor( 100, 100, 100, 30 );
5662
ctx.palette.setColor( QPalette::Text, optionV4.palette.color( QPalette::Disabled, QPalette::Text ) );
5763
}
5864

59-
QStyle *style = QApplication::style();
60-
style->drawPrimitive( QStyle::PE_PanelItemViewItem, &option, painter, NULL );
61-
6265
painter->setRenderHint( QPainter::Antialiasing );
6366
painter->setPen( QColor( 0, 0, 0, 0 ) );
6467
painter->setBrush( QBrush( color ) );
6568
painter->drawRoundedRect( option.rect.left() + 5, option.rect.top() + 5, option.rect.width() - 10, option.rect.height() - 10, 8, 8 );
6669

67-
doc.setHtml( QString( "<span style='font-size:18px;font-weight:bold;'>%1</span><br>%2<br>%3" ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
70+
int titleSize = QApplication::fontMetrics().height() * 1.1;
71+
int textSize = titleSize * 0.85;
72+
73+
doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
6874
doc.setTextWidth( 800 );
6975

7076
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
@@ -84,7 +90,10 @@ QSize QgsWelcomePageItemDelegate::sizeHint( const QStyleOptionViewItem & option,
8490
{
8591
QTextDocument doc;
8692

87-
doc.setHtml( QString( "<span style='font-size:18px;font-weight:bold;'>%1</span><br>%2<br>%3" ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
93+
int titleSize = QApplication::fontMetrics().height() * 1.1;
94+
int textSize = titleSize * 0.85;
95+
96+
doc.setHtml( QString( "<div style='font-size:%1px;'><span style='font-size:%2px;font-weight:bold;'>%3</span><br>%4<br>%5</div>" ).arg( textSize ).arg( titleSize ).arg( index.data( QgsWelcomePageItemsModel::TitleRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::PathRole ).toString() ).arg( index.data( QgsWelcomePageItemsModel::CrsRole ).toString() ) );
8897
doc.setTextWidth( 800 );
8998

9099
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );

0 commit comments

Comments
 (0)
Please sign in to comment.