From cd34e5c7ba369a9832cd851d2882a1351f0fc764 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Tue, 6 Aug 2024 21:28:17 +0200 Subject: [PATCH] Widget/StylesheetStyle: don't draw checkmarks for combobox dropdown The combobox dropdown items are drawn as CE_MenuItem elements. Those elements may have a checkmarks but not when we draw them within a QComboMenuDelegate. Therefore add the same check as for fusion style to avoid drawing a checkmark in a QComboBox dropdown menu. Fixes: QTBUG-127536 Change-Id: Ib22046b018fdf36eb26518899d2427d40b0110b8 Reviewed-by: Axel Spoerl (cherry picked from commit c2d56961394cea799b0caa241c3517ed88aa6c66) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qstylesheetstyle.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 004326e0a44..4045caca770 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3923,10 +3923,16 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } mi.palette.setBrush(QPalette::HighlightedText, mi.palette.brush(QPalette::ButtonText)); - int textRectOffset = m->maxIconWidth; + bool drawCheckMark = mi.menuHasCheckableItems; +#if QT_CONFIG(combobox) + if (qobject_cast(w)) + drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate +#endif + int textRectOffset = 0; if (!mi.icon.isNull()) { renderMenuItemIcon(&mi, p, w, opt->rect, subRule); - } else if (mi.menuHasCheckableItems) { + textRectOffset = m->maxIconWidth; + } else if (drawCheckMark) { const bool checkable = mi.checkType != QStyleOptionMenuItem::NotCheckable; const bool checked = checkable ? mi.checked : false; @@ -3941,7 +3947,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q newMi.rect = cmRect; drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); } - textRectOffset = std::max(textRectOffset, cmRect.width()); + textRectOffset = std::max(m->maxIconWidth, cmRect.width()); } QRect textRect = subRule.contentsRect(opt->rect); @@ -5421,6 +5427,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op return QSize(sz.width(), subRule.size().height()); } if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder() || subRule.hasFont)) { + bool drawCheckMark = mi->menuHasCheckableItems; +#if QT_CONFIG(combobox) + if (qobject_cast(w)) + drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate +#endif QSize sz(csz); if (mi->text.contains(u'\t')) sz.rwidth() += 12; //as in QCommonStyle @@ -5428,7 +5439,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op const int pmSmall = pixelMetric(PM_SmallIconSize); const QSize pmSize = mi->icon.actualSize(QSize(pmSmall, pmSmall)); sz.rwidth() += std::max(mi->maxIconWidth, pmSize.width()) + 4; - } else if (mi->menuHasCheckableItems) { + } else if (drawCheckMark) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); sz.rwidth() += std::max(mi->maxIconWidth, checkmarkRect.width()) + 4;