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>
This commit is contained in:
Christian Ehrlicher 2018-09-28 21:55:47 +02:00
parent f46c9f67ba
commit 4f4a33196d

View File

@ -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();
}
return subRule.boxSize(subRule.adjustSize(QSize(width, csz.height())));
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(sz));
}
}
break;