From 9622c7797a5d7745c55bfe8a09ecf450b2f0cac4 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 20 Dec 2023 09:16:24 +0100 Subject: [PATCH] Styles/fusion: Adjust QSlider painting with modified paint rect When the painting rect is adjusted within an overloaded QSlider::initStyleOption() there are some glitches when using the fusion style: - the tickmarks are not painted inside the specified rect / it is ignored - the glue groove bar is clipped incorrectly Pick-to: 6.6 Fixes: QTBUG-111314 Change-Id: If140c5348031d869b527c6c4850b4a8d34b395c1 Reviewed-by: Axel Spoerl (cherry picked from commit 8594fe1b8dc848d8a2d61197acce67963f5fe20e) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qfusionstyle.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index fe132859a2c..7b0d391c896 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2754,10 +2754,11 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption if (slider->upsideDown) clipRect = QRect(handle.right(), groove.top(), groove.right() - handle.right(), groove.height()); else - clipRect = QRect(groove.left(), groove.top(), handle.left(), groove.height()); + clipRect = QRect(groove.left(), groove.top(), + handle.left() - slider->rect.left(), groove.height()); } else { if (slider->upsideDown) - clipRect = QRect(groove.left(), handle.bottom(), groove.width(), groove.height() - handle.bottom()); + clipRect = QRect(groove.left(), handle.bottom(), groove.width(), groove.height() - (handle.bottom() - slider->rect.top())); else clipRect = QRect(groove.left(), groove.top(), groove.width(), handle.top() - groove.top()); } @@ -2768,6 +2769,8 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption } if (option->subControls & SC_SliderTickmarks) { + painter->save(); + painter->translate(slider->rect.x(), slider->rect.y()); painter->setPen(outline); int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget); int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget); @@ -2823,6 +2826,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption v = nextInterval; } painter->drawLines(lines); + painter->restore(); } // draw handle if ((option->subControls & SC_SliderHandle) ) {