Fix icon-only delegate

The delegate was still rendering display text. But we didn't realize
because the only place where this delegate was used was returning a
QVariant() for DisplayText role earlier. Once we started returning a
valid QString (for copy-paste purposes), this bug showed up.

This didn't work because we further delegate the actual painting to
the base QStyledItemDelegate which re-initializes option.features
from the item index values, so removing HasDisplay does not work.

The fix is to override the displayText() to return a null string.
This commit is contained in:
Srivats P 2023-10-13 12:16:03 +05:30
parent 1e8486991d
commit ebe6aef62d

View File

@ -31,9 +31,13 @@ class IconOnlyDelegate : public QStyledItemDelegate
{ {
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
opt.decorationPosition = QStyleOptionViewItem::Top; opt.decorationPosition = QStyleOptionViewItem::Top;
opt.features &= ~QStyleOptionViewItem::HasDisplay;
QStyledItemDelegate::paint(painter, opt, index); QStyledItemDelegate::paint(painter, opt, index);
} }
QString displayText(const QVariant&, const QLocale&) const
{
return QString();
}
}; };
#endif #endif