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 <axel.spoerl@qt.io>
This commit is contained in:
Christian Ehrlicher 2024-10-31 17:59:50 +01:00
parent 4b9631359b
commit 44634c58ce

View File

@ -3948,10 +3948,9 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (qobject_cast<const QComboBox *>(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;