diff options
| author | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-07-15 10:47:09 +0200 |
|---|---|---|
| committer | Wladimir Leuschner <wladimir.leuschner@qt.io> | 2024-07-15 16:17:29 +0200 |
| commit | 384acdc1cf2cc6472c9eb9d2d79077736ded0e92 (patch) | |
| tree | 9f26403589c5b7369b3b4e0b058733c3200eb5d5 /src | |
| parent | 1ab33d575a6993ceb8d9482c20d5c7d6deb252ea (diff) | |
QWindows11Style: Use QProgressStyleAnimation for QProgressBar
Currently for an indeterminate QProgressBar in QWindows11Style, a busy
drawing is triggered, consuming more CPU resources than necessary. This
patch avoids the busy drawing by using QProgressStyleAnimation, which
only triggers a redraw for specified Fps.
Fixes: QTBUG-127112
Pick-to: 6.8 6.7
Change-Id: I46da8ffcb849563c771dbc72af4c7e8b306b4802
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/styles/modernwindows/qwindows11style.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index cbbc0ad13dc..f968b219125 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -1295,6 +1295,13 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op const qreal offset = (orientation == Qt::Horizontal && int(rect.height()) % 2 == 0) || (orientation == Qt::Vertical && int(rect.width()) % 2 == 0) ? 0.5 : 0.0; + if (isIndeterminate) { + if (!d->animation(option->styleObject)) + d->startAnimation(new QProgressStyleAnimation(d->animationFps, option->styleObject)); + } else { + d->stopAnimation(option->styleObject); + } + if (!isIndeterminate) { fillPercentage = ((float(progbaropt->progress) - float(progbaropt->minimum)) / (float(progbaropt->maximum) - float(progbaropt->minimum))); if (orientation == Qt::Horizontal) { @@ -1309,22 +1316,23 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op rect.setHeight(oldHeight * fillPercentage); } } else { - auto elapsedTime = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()); - fillPercentage = (elapsedTime.time_since_epoch().count() % 5000)/(5000.0f*0.75); - if (orientation == Qt::Horizontal) { - float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.width(), float(rect.width())); - float barEnd = qMin(fillPercentage * rect.width(), float(rect.width())); - rect = QRect(QPoint(rect.left() + barBegin, rect.top()), QPoint(rect.left() + barEnd, rect.bottom())); - rect.setHeight(progressBarThickness); - rect.moveTop(center.y() - progressBarHalfThickness - offset); - } else { - float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.height(), float(rect.height())); - float barEnd = qMin(fillPercentage * rect.height(), float(rect.height())); - rect = QRect(QPoint(rect.left(), rect.bottom() - barEnd), QPoint(rect.right(), rect.bottom() - barBegin)); - rect.setWidth(progressBarThickness); - rect.moveLeft(center.x() - progressBarHalfThickness - offset); + if (qobject_cast<QProgressStyleAnimation *>(d->animation(option->styleObject))) { + auto elapsedTime = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()); + fillPercentage = (elapsedTime.time_since_epoch().count() % 5000)/(5000.0f*0.75); + if (orientation == Qt::Horizontal) { + float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.width(), float(rect.width())); + float barEnd = qMin(fillPercentage * rect.width(), float(rect.width())); + rect = QRect(QPoint(rect.left() + barBegin, rect.top()), QPoint(rect.left() + barEnd, rect.bottom())); + rect.setHeight(progressBarThickness); + rect.moveTop(center.y() - progressBarHalfThickness - offset); + } else { + float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.height(), float(rect.height())); + float barEnd = qMin(fillPercentage * rect.height(), float(rect.height())); + rect = QRect(QPoint(rect.left(), rect.bottom() - barEnd), QPoint(rect.right(), rect.bottom() - barBegin)); + rect.setWidth(progressBarThickness); + rect.moveLeft(center.x() - progressBarHalfThickness - offset); + } } - const_cast<QWidget*>(widget)->update(); } if (progbaropt->invertedAppearance && orientation == Qt::Horizontal) rect.moveLeft(originalRect.width() * (1.0 - fillPercentage)); |
