diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index 015523c4e57..c685ef2b634 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -111,29 +111,33 @@ bool QProgressBarPrivate::repaintRequired() const if (value == lastPaintedValue) return false; - const auto valueDifference = qAbs(qint64(value) - lastPaintedValue); - // Check if the text needs to be repainted + const int valueDifference = qAbs(value - lastPaintedValue); + if (value == minimum || value == maximum) return true; - const auto totalSteps = qint64(maximum) - minimum; + const int totalSteps = maximum - minimum; + + const int currentPercentage = (value - minimum) * 100 / totalSteps; + const int lastPaintedPercentage = (lastPaintedValue - minimum) * 100 / totalSteps; + + const int percentageChangeConstant = 1; + const bool percentageChanged = (qAbs(currentPercentage - lastPaintedPercentage) >= percentageChangeConstant); + if (textVisible) { if (format.contains("%v"_L1)) return true; - if (format.contains("%p"_L1) && valueDifference >= qAbs(totalSteps / 100)) + if (format.contains("%p"_L1) && percentageChanged) return true; } - // Check if the bar needs to be repainted + // Check if the bar needs to be repainted based on pixel-level differences QStyleOptionProgressBar opt; q->initStyleOption(&opt); - int cw = q->style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, q); QRect groove = q->style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, q); - // This expression is basically - // (valueDifference / (maximum - minimum) > cw / groove.width()) - // transformed to avoid integer division. int grooveBlock = (q->orientation() == Qt::Horizontal) ? groove.width() : groove.height(); - return valueDifference * grooveBlock > cw * totalSteps; + const double pixelSize = static_cast(totalSteps) / grooveBlock; + return valueDifference > pixelSize; } /*!