From 905dfd39153b4ba0650cd3144769ba8a1fd759b7 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. Fixes: QTBUG-130704 Task-number: QTBUG-127536 Change-Id: I826cdce5ead5da0d1e5fdd8a5e2a6972306457b2 Reviewed-by: Axel Spoerl (cherry picked from commit 44634c58ceb79a63102592ec4e1b8a7399a8a660) Reviewed-by: Qt Cherry-pick Bot --- 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 4045caca770..a1824a1df7b 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3928,10 +3928,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;