@@ -36,6 +36,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
36
36
painter->save ();
37
37
38
38
QTextDocument doc;
39
+ QPixmap icon = qvariant_cast<QPixmap>( index.data ( Qt::DecorationRole ) );
40
+
39
41
QAbstractTextDocumentLayout::PaintContext ctx;
40
42
QStyleOptionViewItemV4 optionV4 = option;
41
43
@@ -71,9 +73,8 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
71
73
int textSize = titleSize * 0.85 ;
72
74
73
75
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 );
76
+ doc.setTextWidth ( option. rect . width () - ( !icon. isNull () ? icon. width () + 35 : 35 ) );
75
77
76
- QPixmap icon = qvariant_cast<QPixmap>( index.data ( Qt::DecorationRole ) );
77
78
if ( !icon.isNull () )
78
79
{
79
80
painter->drawPixmap ( option.rect .left () + 10 , option.rect .top () + 10 , icon );
@@ -89,16 +90,25 @@ void QgsWelcomePageItemDelegate::paint( QPainter* painter, const QStyleOptionVie
89
90
QSize QgsWelcomePageItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const
90
91
{
91
92
QTextDocument doc;
93
+ QPixmap icon = qvariant_cast<QPixmap>( index.data ( Qt::DecorationRole ) );
94
+
95
+ int width;
96
+ if ( option.rect .width () < 450 )
97
+ {
98
+ width = 450 ;
99
+ }
100
+ else
101
+ {
102
+ width = option.rect .width ();
103
+ }
92
104
93
105
int titleSize = QApplication::fontMetrics ().height () * 1.1 ;
94
106
int textSize = titleSize * 0.85 ;
95
107
96
108
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 );
98
-
99
- QPixmap icon = qvariant_cast<QPixmap>( index.data ( Qt::DecorationRole ) );
109
+ doc.setTextWidth ( width - ( !icon.isNull () ? icon.width () + 35 : 35 ) );
100
110
101
- return QSize ( option. rect . width () , qMax ( doc.size ().height () + 10 , ( double )icon.height () ) + 20 );
111
+ return QSize ( width, qMax ( doc.size ().height () + 10 , ( double )icon.height () ) + 20 );
102
112
}
103
113
104
114
QgsWelcomePageItemsModel::QgsWelcomePageItemsModel ( QObject* parent )
0 commit comments