Skip to content

Commit 80bb62c

Browse files
committedOct 2, 2015
Merge pull request #2344 from nirvn/welcome_page_hidpi_fix
[welcome page] fix font size on HiDPI display and improve disabled item style
2 parents 48ce385 + 1fdfe30 commit 80bb62c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed
 

‎src/app/qgswelcomepageitemsmodel.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,34 @@ 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() ) );
68-
doc.setTextWidth( 800 );
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() ) );
74+
doc.setTextWidth( 2800 );
6975

7076
QPixmap icon = qvariant_cast<QPixmap>( index.data( Qt::DecorationRole ) );
7177
if ( !icon.isNull() )
@@ -84,8 +90,11 @@ 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() ) );
88-
doc.setTextWidth( 800 );
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() ) );
97+
doc.setTextWidth( 2800 );
8998

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

0 commit comments

Comments
 (0)
Please sign in to comment.