From ea0e0a865237983b484ed88447b9fc4c473e2759 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Fri, 11 Feb 2022 14:01:27 +0100 Subject: [PATCH] Eliminate double arrow in QToolButton - InstantPopup mode is set and - application uses a stylesheet that does not apply to QToolButton Task-number: QTBUG-100401 Pick-to: 6.3 6.2 Change-Id: Iadf752ad9280d59763f4efc1938927a9b83e6ad9 Reviewed-by: Volker Hilsheimer --- src/widgets/styles/qstylesheetstyle.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 3ad68067af..6ae621a85b 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3306,18 +3306,18 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC toolOpt.features &= ~QStyleOptionToolButton::Arrow; toolOpt.text = QString(); // we need to draw the arrow and the text ourselves } - const bool drawDropDown = tool->features & QStyleOptionToolButton::MenuButtonPopup; + bool drawDropDown = tool->features & QStyleOptionToolButton::MenuButtonPopup; bool customDropDown = drawDropDown && hasStyleRule(w, PseudoElement_ToolButtonMenu); bool customDropDownArrow = false; - const bool drawMenuIndicator = tool->features & QStyleOptionToolButton::HasMenu; + bool drawMenuIndicator = tool->features & QStyleOptionToolButton::HasMenu; if (customDropDown) { toolOpt.subControls &= ~QStyle::SC_ToolButtonMenu; customDropDownArrow = hasStyleRule(w, PseudoElement_ToolButtonMenuArrow); if (customDropDownArrow) toolOpt.features &= ~(QStyleOptionToolButton::Menu | QStyleOptionToolButton::HasMenu); } - bool customMenuIndicator = (!customDropDown && drawMenuIndicator) - && hasStyleRule(w, PseudoElement_ToolButtonMenuIndicator); + const bool customMenuIndicator = (!customDropDown && drawMenuIndicator) + && hasStyleRule(w, PseudoElement_ToolButtonMenuIndicator); if (customMenuIndicator) toolOpt.features &= ~QStyleOptionToolButton::HasMenu; @@ -3335,11 +3335,18 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC rule.drawBackground(p, toolOpt.rect); } + // Let base or windows style draw the button + // set drawDropDown and drawMenuIndicator flags to false, + // unless customDropDownArrow needs to be drawn if (rule.baseStyleCanDraw() && !(tool->features & QStyleOptionToolButton::Arrow)) { baseStyle()->drawComplexControl(cc, &toolOpt, p, w); } else { QWindowsStyle::drawComplexControl(cc, &toolOpt, p, w); } + if (!customDropDownArrow) { + drawDropDown = false; + drawMenuIndicator = false; + } } else { rule.drawRule(p, opt->rect); toolOpt.rect = rule.contentsRect(opt->rect); @@ -3349,6 +3356,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC } const QRect cr = toolOpt.rect; + // Draw DropDownButton unless drawn before if (drawDropDown) { if (opt->subControls & QStyle::SC_ToolButtonMenu) { QRenderRule subRule = renderRule(w, opt, PseudoElement_ToolButtonMenu);