diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-09-28 21:55:47 +0200 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2018-10-03 19:36:31 +0000 |
commit | 4f4a33196dc37a9405a8dbd20a1e63d36e000d2f (patch) | |
tree | 056bb30f8151c1e88639ac513b06a8940f721dc8 /src/widgets/styles/qstylesheetstyle.cpp | |
parent | f46c9f67bafd01654ac41867144c9c476a0a5649 (diff) |
QStyleSheetStyle: use specified font property from css for QMenu
A font property specified in the css was used while drawing the QMenu
action text but not within sizeFromContents() which results in a wrong
size of the menu rect used for drawing.
Fix it by mimic the rect calculation from
QMenuPrivate::updateActionRects().
Fixes: QTBUG-70648
Change-Id: I5cf4f8b679c69197437393965c0bc6326f1c6c3a
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/styles/qstylesheetstyle.cpp')
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 5c9d19a49d..325a2f024a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -5075,21 +5075,27 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op QRenderRule subRule = renderRule(w, opt, pe); if ((pe == PseudoElement_MenuSeparator) && subRule.hasContentsSize()) { return QSize(sz.width(), subRule.size().height()); - } else if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder())) { - int width = csz.width(); + } + if ((pe == PseudoElement_Item) && (subRule.hasBox() || subRule.hasBorder() || subRule.hasFont)) { + QSize sz(csz); if (mi->text.contains(QLatin1Char('\t'))) - width += 12; //as in QCommonStyle + sz.rwidth() += 12; //as in QCommonStyle bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - width += checkmarkRect.width(); + sz.rwidth() += checkmarkRect.width(); } if (!mi->icon.isNull()) { QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize)); - width += pixmap.width(); + sz.rwidth() += pixmap.width(); + } + if (subRule.hasFont) { + QFontMetrics fm(subRule.font); + const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); + sz = sz.expandedTo(r.size()); } - return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height()))); + return subRule.boxSize(subRule.adjustSize(sz)); } } break; |