From 308845cd720969a5f3456caa8cf72023f120aecf Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 9 Jun 2021 16:54:27 +0200 Subject: [PATCH] In headers with only the arrow styled, prevent overlapping with text A style sheet that styles only the header arrow, but not the header section or label, resulted in an overlapped text and header if the text was also right aligned. To prevent this, add the space required by the arrow to the size calculation, and shorten the space accordingly before rendering the right-aligned label. Make corresponding adjustments to vertical headers with bottom-aligned labels. Fixes: QTBUG-84117 Pick-to: 6.2 Change-Id: I782d9538b695ad55d2d70b6d230f66059598768f Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qstylesheetstyle.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 59b00917677..d729eb631aa 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3984,6 +3984,14 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q if (const QStyleOptionHeader *header = qstyleoption_cast(opt)) { QStyleOptionHeader hdr(*header); 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()); + } subRule.configurePalette(&hdr.palette, QPalette::ButtonText, QPalette::Button); if (subRule.hasFont) { QFont oldFont = p->font(); @@ -5132,8 +5140,17 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op } return subRule.size(sz); } - return subRule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) - : QWindowsStyle::sizeFromContents(ct, opt, sz, w); + sz = subRule.baseStyleCanDraw() ? baseStyle()->sizeFromContents(ct, opt, sz, w) + : QWindowsStyle::sizeFromContents(ct, opt, sz, w); + if (hasStyleRule(w, PseudoElement_HeaderViewDownArrow) + || hasStyleRule(w, PseudoElement_HeaderViewUpArrow)) { + const QRect arrowRect = subElementRect(SE_HeaderArrow, opt, w); + if (hdr->orientation == Qt::Horizontal) + sz.rwidth() += arrowRect.width(); + else + sz.rheight() += arrowRect.height(); + } + return sz; } } break;