@@ -102,15 +102,13 @@ class IconViewDelegate : public QStyledItemDelegate
102
102
{
103
103
QIcon icon = qvariant_cast<QIcon>(index .data (Qt::DecorationRole));
104
104
QSize iconsize = icon.actualSize (option.decorationSize );
105
- QRect item = option.rect ;
106
- QRect txtRect (item.left (), item.top ()+iconsize.height (),
107
- item.width (), item.height ()-iconsize.height ());
105
+ int width = qMax (iconsize.width (), option.fontMetrics .averageCharWidth () * 13 );
106
+ QRect txtRect (0 , 0 , width, option.rect .height ());
108
107
QSize txtsize = option.fontMetrics .boundingRect (txtRect,
109
108
Qt::AlignCenter|Qt::TextWrapAnywhere,
110
109
index .data ().toString ()).size ();
111
- int width = txtsize.width ();
112
- if (width<iconsize.width ()) { width = iconsize.width (); }
113
- return QSize (width+10 ,txtsize.height ()+iconsize.height ());
110
+ QSize size (width, txtsize.height ()+iconsize.height ());
111
+ return size;
114
112
}
115
113
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
116
114
{
@@ -119,8 +117,8 @@ class IconViewDelegate : public QStyledItemDelegate
119
117
QRect item = option.rect ;
120
118
QRect iconRect (item.left ()+(item.width ()/2 )-(iconsize.width ()/2 ),
121
119
item.top (), iconsize.width (), iconsize.height ());
122
- QRect txtRect (item.left ()+ 5 , item.top ()+iconsize.height (),
123
- item.width ()- 10 , item.height ()-iconsize.height ());
120
+ QRect txtRect (item.left (), item.top ()+iconsize.height (),
121
+ item.width (), item.height ()-iconsize.height ());
124
122
QBrush txtBrush = qvariant_cast<QBrush>(index .data (Qt::ForegroundRole));
125
123
bool isSelected = option.state & QStyle::State_Selected;
126
124
bool isEditing = _isEditing && index ==_index;
0 commit comments