From 656576d3b43b0b46045254a3ba884f1b2b9c0a2e Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 29 Dec 2023 15:27:46 +0100 Subject: [PATCH] CommonStyle/QSlider: use drawLines() instead single drawLine() calls Optimize the painting of the tickmarks by collecting all lines to draw in a vector and then passing all to the painter instead calling drawLine() for every single tickmark. Change-Id: Ic75e733a02fbf6143d21d4630f6a6d6de913f16c Reviewed-by: Axel Spoerl (cherry picked from commit 83ab7d21150115fbbe954af7d87f1597bf65d206) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qfusionstyle.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 2a5798279f3..f08f5ec9330 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -2785,6 +2785,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption int v = slider->minimum; int len = proxy()->pixelMetric(PM_SliderLength, slider, widget); + QVector lines; while (v <= slider->maximum + 1) { if (v == slider->maximum + 1 && interval == 1) break; @@ -2798,21 +2799,21 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption if (horizontal) { if (ticksAbove) { - painter->drawLine(pos, slider->rect.top() + extra, - pos, slider->rect.top() + tickSize); + lines += QLine(pos, slider->rect.top() + extra, + pos, slider->rect.top() + tickSize); } if (ticksBelow) { - painter->drawLine(pos, slider->rect.bottom() - extra, - pos, slider->rect.bottom() - tickSize); + lines += QLine(pos, slider->rect.bottom() - extra, + pos, slider->rect.bottom() - tickSize); } } else { if (ticksAbove) { - painter->drawLine(slider->rect.left() + extra, pos, - slider->rect.left() + tickSize, pos); + lines += QLine(slider->rect.left() + extra, pos, + slider->rect.left() + tickSize, pos); } if (ticksBelow) { - painter->drawLine(slider->rect.right() - extra, pos, - slider->rect.right() - tickSize, pos); + lines += QLine(slider->rect.right() - extra, pos, + slider->rect.right() - tickSize, pos); } } // in the case where maximum is max int @@ -2821,6 +2822,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption break; v = nextInterval; } + painter->drawLines(lines); } // draw handle if ((option->subControls & SC_SliderHandle) ) {