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)); } }