From fb8701cb8b1972d5ca6ffc383a436786bc170d16 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 2 Jan 2023 17:41:50 +0100 Subject: 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 Reviewed-by: Santhosh Kumar --- src/widgets/itemviews/qstyleditemdelegate.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/widgets/itemviews') 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(*value); + if (option->icon.isNull()) { + option->features &= ~QStyleOptionViewItem::HasDecoration; + break; + } QIcon::Mode mode; if (!(option->state & QStyle::State_Enabled)) mode = QIcon::Disabled; -- cgit v1.2.3