From 97ac281c1d70dcfbb137e5a83e24a747e9510116 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 4 Dec 2019 17:15:30 +0100 Subject: QStyleSheetStyle: properly honor checkmark size when drawing a QMenu When drawing a QMenu which is checkable but does not have an icon somewhere, the width of the (possible) checkmark was not considered during drawing and the text was drawn over the checkmark. Also the wrong state was checked for drawing the checked icon (if one was given). Fixes: QTBUG-80506 Task-number: QTBUG-78238 Change-Id: Icf8aa37aab424564054d3549defee93eb0d7c1a4 Reviewed-by: Eirik Aavitsland --- src/widgets/styles/qstylesheetstyle.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/widgets/styles/qstylesheetstyle.cpp') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 3f57992311..aab4b74c4b 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3711,6 +3711,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q bool dis = !(opt->state & QStyle::State_Enabled), act = opt->state & QStyle::State_Selected; + int textRectOffset = m->maxIconWidth; if (!mi.icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) @@ -3736,19 +3737,21 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q p->drawPixmap(pmr.topLeft(), pixmap); } else if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); + const QRect cmRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); if (subSubRule.hasDrawable() || checked) { QStyleOptionMenuItem newMi = mi; if (!dis) newMi.state |= State_Enabled; - if (act) + if (mi.checked) newMi.state |= State_On; - newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); + newMi.rect = cmRect; drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); } + textRectOffset = std::max(textRectOffset, cmRect.width()); } QRect textRect = subRule.contentsRect(opt->rect); - textRect.setLeft(textRect.left() + m->maxIconWidth); + textRect.setLeft(textRect.left() + textRectOffset); textRect.setWidth(textRect.width() - mi.tabWidth); const QRect vTextRect = visualRect(opt->direction, m->rect, textRect); -- cgit v1.2.3 From 03dc30acca4976c716c723ff46d503d35459b2a0 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Tue, 3 Dec 2019 13:39:08 +0100 Subject: Fix QPushButton style sheet style for overlay (content) image Unlike comparable widgets like QLabel or QFrame, QPushButton would not render a content image specified in the stylesheet, unless a border style was also specified. Fix by explicitly rendering the content image, if set, in the native-border codepath also. Although the doc warns about the QPushButton border style having to be set in order for the background styling to take effect (since the native border painting otherwise hides it), the previous behavior does seem unexpected. Fixes: QTBUG-72029 Change-Id: I8b979b010515dab4dcf2f00344a187c87eeec096 Reviewed-by: Friedemann Kleint Reviewed-by: Christian Ehrlicher --- src/widgets/styles/qstylesheetstyle.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/widgets/styles/qstylesheetstyle.cpp') diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index aab4b74c4b..98c85684ae 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3493,6 +3493,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q } else { QWindowsStyle::drawControl(ce, &btnOpt, p, w); } + rule.drawImage(p, rule.contentsRect(opt->rect)); if (!customMenu) return; } else { -- cgit v1.2.3