summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-01-02 17:41:50 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-01-04 13:42:06 +0100
commitfb8701cb8b1972d5ca6ffc383a436786bc170d16 (patch)
tree39ce15217f73359ded121f0e98a63dd2286dce26 /src/widgets/itemviews
parent84a68ef75ce8a8e5b90d799c90905cc998c7c2f6 (diff)
QListView: Prevent infinite loop when wrapping text of item with null-icon
If an item in a list view has a null icon, then the decorationSize gets calculated as -1, -1. The style would then try to wrap the text to a lineWidth of -1, ending up in an infinite loop in viewItemTextLayout. To prevent that, don't set the HasDecoration flag of the style option when the icon is null, and don't fall back ot the decorationSize unless the flag is set. Add a test for this particular item configuration. This also fixes the widget baseline test with styles that don't provide all standard icons. Pick-to: 6.5 Change-Id: I691db6abede9a9b2ad300f3ee7fbfdae5fb6097f Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qstyleditemdelegate.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp
index 7442fc58c8..038b0bdcd0 100644
--- a/src/widgets/itemviews/qstyleditemdelegate.cpp
+++ b/src/widgets/itemviews/qstyleditemdelegate.cpp
@@ -285,6 +285,10 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option,
switch (value->userType()) {
case QMetaType::QIcon: {
option->icon = qvariant_cast<QIcon>(*value);
+ if (option->icon.isNull()) {
+ option->features &= ~QStyleOptionViewItem::HasDecoration;
+ break;
+ }
QIcon::Mode mode;
if (!(option->state & QStyle::State_Enabled))
mode = QIcon::Disabled;