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.

Fixes: QTBUG-115356
Change-Id: I33e83022bea9e3a531ac8e1651d8655076d88b4b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 5436c4a363aa856180ce2949c2f5eeed451abfa9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 4003ca0d326fc41fd977f83f1e9faea8f774720d)
bb10
Christian Ehrlicher 2024-11-08 22:28:36 +01:00 committed by Qt Cherry-pick Bot
parent 7ae07f0eef
commit f4537faab8
1 changed files with 5 additions and 5 deletions

View File

@ -5436,6 +5436,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()) {
@ -5449,11 +5454,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));
}
}