From 0188953c6d19e320beb04f735ec969eecb129f4c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 22 Nov 2024 21:35:42 +0100 Subject: [PATCH] Fusion style: misc speedup drawing indeterminate progress bar When drawing an indeterminate progress bar, QPainter::drawLine() is called very often. Avoid it by first calculating all lines and then call QPainter::drawLines() once with all lines to draw. Change-Id: I51ce23236b945b30da649fd06aad60676321e403 Reviewed-by: Volker Hilsheimer (cherry picked from commit 0eedffa01daed077aba4781b240068929cf768be) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qfusionstyle.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 95e52b41ef5..1b0e18d8b93 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1300,14 +1300,21 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->setPen(QPen(highlightedGradientStartColor, 9.0)); painter->setClipRect(progressBar.adjusted(1, 1, -1, -1)); #if QT_CONFIG(animation) - if (QProgressStyleAnimation *animation = qobject_cast(d->animation(option->styleObject))) - step = animation->animationStep() % 22; - else - (const_cast(d))->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); + if (QProgressStyleAnimation *animation = + qobject_cast(d->animation(option->styleObject))) { + step = animation->animationStep() % 22; + } else { + (const_cast(d))->startAnimation( + new QProgressStyleAnimation(d->animationFps, option->styleObject) + ); + } #endif - for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22) - painter->drawLine(x + step, progressBar.bottom() + 1, - x + rect.height() + step, progressBar.top() - 2); + QVarLengthArray lines; + for (int x = progressBar.left() - rect.height(); x < rect.right() ; x += 22) { + lines.emplace_back(x + step, progressBar.bottom() + 1, + x + rect.height() + step, progressBar.top() - 2); + } + painter->drawLines(lines.data(), lines.count()); } } if (!indeterminate && !complete) {