From 0af27bf8364b0200a6f2c92e6b774d377644cd44 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 24 Sep 2023 19:19:47 +0200 Subject: [PATCH] ItemViews/css: Honor size for sort indicator only when there is one When using css the size for the sort indicator is not honored correctly and therefore the header view text overlaps the sort inidcator. This patch reduces the available with for the text when (and only when) there is a sort indicator shown), also for the size hint. Fixes: QTBUG-115486 Pick-to: 6.5 Change-Id: Ic865bceaf98cd303490d821ecfb033abb8d6ba2a Reviewed-by: Axel Spoerl (cherry picked from commit 230ff021a14816519b175d02d3400541ddd2abad) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qstylesheetstyle.cpp | 30 +++++++++++++++++++------ 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index e3ca85d29e4..1b7db3b5b1d 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4127,11 +4127,13 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection); if (hasStyleRule(w, PseudoElement_HeaderViewUpArrow) || hasStyleRule(w, PseudoElement_HeaderViewDownArrow)) { - const QRect arrowRect = subElementRect(SE_HeaderArrow, opt, w); - if (hdr.orientation == Qt::Horizontal) - hdr.rect.setWidth(hdr.rect.width() - arrowRect.width()); - else - hdr.rect.setHeight(hdr.rect.height() - arrowRect.height()); + if (hdr.sortIndicator != QStyleOptionHeader::None) { + const QRect arrowRect = subElementRect(SE_HeaderArrow, opt, w); + if (hdr.orientation == Qt::Horizontal) + hdr.rect.setWidth(hdr.rect.width() - arrowRect.width()); + else + hdr.rect.setHeight(hdr.rect.height() - arrowRect.height()); + } } subRule.configurePalette(&hdr.palette, QPalette::ButtonText, QPalette::Button); if (subRule.hasFont) { @@ -6224,8 +6226,22 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c case SE_HeaderLabel: { QRenderRule subRule = renderRule(w, opt, PseudoElement_HeaderViewSection); - if (subRule.hasBox() || !subRule.hasNativeBorder()) - return subRule.contentsRect(opt->rect); + if (subRule.hasBox() || !subRule.hasNativeBorder()) { + auto r = subRule.contentsRect(opt->rect); + if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { + // Subtract width needed for arrow, if there is one + if (header->sortIndicator != QStyleOptionHeader::None) { + const auto arrowRect = subElementRect(SE_HeaderArrow, opt, w); + if (arrowRect.isValid()) { + if (opt->state & State_Horizontal) + r.setWidth(r.width() - arrowRect.width()); + else + r.setHeight(r.height() - arrowRect.height()); + } + } + } + return r; + } } break;