From 44634c58ceb79a63102592ec4e1b8a7399a8a660 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 31 Oct 2024 17:59:50 +0100 Subject: [PATCH] QStyleSheetStyle: fix drawing CE_MenuItem with icons Drawing a CE_MenuItem with icons when some entries don't have an icon resulted in a misalignment of the text for the entries without an icon. Fix it by honoring QStyleOptionMenuItem::maxIconWidth which is set by QMenu depending on whether on if it's entries has an icon or not. Pick-to: 6.8 Fixes: QTBUG-130704 Task-number: QTBUG-127536 Change-Id: I826cdce5ead5da0d1e5fdd8a5e2a6972306457b2 Reviewed-by: Axel Spoerl --- src/widgets/styles/qstylesheetstyle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 79816645e16..31d913cdcfc 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3948,10 +3948,9 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q if (qobject_cast(w)) drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate #endif - int textRectOffset = 0; + int textRectOffset = m->maxIconWidth; if (!mi.icon.isNull()) { renderMenuItemIcon(&mi, p, w, opt->rect, subRule); - textRectOffset = m->maxIconWidth; } else if (drawCheckMark) { const bool checkable = mi.checkType != QStyleOptionMenuItem::NotCheckable; const bool checked = checkable ? mi.checked : false;