From 4003ca0d326fc41fd977f83f1e9faea8f774720d Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 8 Nov 2024 22:28:36 +0100 Subject: [PATCH] QStyleSheetStyle: fix CT_MenuItem with custom font When a menu has a custom font size set, the size was adjusted to reflect this *after* the additional widths for icon or checkmark was added. When the used font is larger, the additional width added for the icon or checkmark will not be honored then. Therefore the size with the new font has to be added before adding the size for the icon/checkmark. Pick-to: 6.8 Fixes: QTBUG-115356 Change-Id: I33e83022bea9e3a531ac8e1651d8655076d88b4b Reviewed-by: Volker Hilsheimer (cherry picked from commit 5436c4a363aa856180ce2949c2f5eeed451abfa9) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qstylesheetstyle.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index f8b3ff027ec..f8417f0fe03 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -5457,6 +5457,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op drawCheckMark = false; // ignore the checkmarks provided by the QComboMenuDelegate #endif QSize sz(csz); + if (subRule.hasFont) { + QFontMetrics fm(subRule.font.resolve(mi->font)); + const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); + sz = sz.expandedTo(r.size()); + } if (mi->text.contains(u'\t')) sz.rwidth() += 12; //as in QCommonStyle if (!mi->icon.isNull()) { @@ -5470,11 +5475,6 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op } else { sz.rwidth() += mi->maxIconWidth; } - if (subRule.hasFont) { - QFontMetrics fm(subRule.font.resolve(mi->font)); - const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); - sz = sz.expandedTo(r.size()); - } return subRule.boxSize(subRule.adjustSize(sz)); } }