From 7763b83c4cb16f9e6ed4dc278f0804bdde42075e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 20 Mar 2023 20:09:48 +0100 Subject: [PATCH] Widgets/Styles: pass correct style option struct to subelements QHeaderView is using QStyleOptionHeaderV2 which should later be used in the subelements drawings. But since the subelement rect must be adjusted, a copy is done - sadly only to QStyleOptionHeader so we're loosing the V2 information. Therefore explicitly check if it's a V2 and copy it over to the correct structure. Pick-to: 6.5 6.2 Fixes: QTBUG-97571 Change-Id: I1482f118e2114cd6ef21c2a800785bd9910c1c5b Reviewed-by: Volker Hilsheimer Reviewed-by: Qt CI Bot --- src/widgets/styles/qcommonstyle.cpp | 8 +++++++- src/widgets/styles/qstyleoption.h | 1 + src/widgets/styles/qstylesheetstyle.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index f4a8d1f1ea..28731aaca1 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -2183,7 +2183,13 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, QRegion clipRegion = p->clipRegion(); p->setClipRect(opt->rect); proxy()->drawControl(CE_HeaderSection, header, p, widget); - QStyleOptionHeader subopt = *header; + // opt can be a QStyleOptionHeaderV2 and we must pass it to the subcontrol drawings + QStyleOptionHeaderV2 subopt; + QStyleOptionHeader &v1Copy = subopt; + if (auto v2 = qstyleoption_cast(opt)) + subopt = *v2; + else + v1Copy = *header; subopt.rect = subElementRect(SE_HeaderLabel, header, widget); if (subopt.rect.isValid()) proxy()->drawControl(CE_HeaderLabel, &subopt, p, widget); diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h index c41256fe35..6841a81b84 100644 --- a/src/widgets/styles/qstyleoption.h +++ b/src/widgets/styles/qstyleoption.h @@ -193,6 +193,7 @@ protected: QStyleOptionHeader(int version); }; +// ### Qt7: merge with QStyleOptionHeader class Q_WIDGETS_EXPORT QStyleOptionHeaderV2 : public QStyleOptionHeader { public: diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 70217127c3..86a174a342 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4101,7 +4101,12 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q case CE_HeaderLabel: if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { - QStyleOptionHeader hdr(*header); + QStyleOptionHeaderV2 hdr; + QStyleOptionHeader &v1Copy = hdr; + if (auto v2 = qstyleoption_cast(opt)) + hdr = *v2; + else + v1Copy = *header; QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection); if (hasStyleRule(w, PseudoElement_HeaderViewUpArrow) || hasStyleRule(w, PseudoElement_HeaderViewDownArrow)) {