From 3f996edbb69a575267a4ff816f09510f14729149 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 5 Jan 2017 09:12:10 +0100 Subject: QPixmapStyle: do not assume minimum == 0 when painting progress bars The arithmetic used to calculate the size of the progress bar fill in QPixmapStyle assumed minimum == 0, but that does not necessarily hold, since the minimum value is user-defined. So, fix the arithmetic to take the minimum into account, taking care, as done elsewhere, to avoid signed integer and qreal=float overflows, by using qint64 and double, respectively. [ChangeLog][QtWidgets][QPixmapStyle] Now handles progress bars with minimum != 0 correctly. Change-Id: I738ded56e8234716c36a5e9fde15bae691c43a35 Reviewed-by: David Faure --- src/widgets/styles/qpixmapstyle.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qpixmapstyle.cpp b/src/widgets/styles/qpixmapstyle.cpp index e973a96a91..ce37065fb6 100644 --- a/src/widgets/styles/qpixmapstyle.cpp +++ b/src/widgets/styles/qpixmapstyle.cpp @@ -819,11 +819,14 @@ void QPixmapStyle::drawProgressBarFill(const QStyleOption *option, drawCachedPixmap(vertical ? PB_VComplete : PB_HComplete, option->rect, painter); } else { - if (pbar->progress == 0) + if (pbar->progress == pbar->minimum) return; - const int maximum = pbar->maximum; - const qreal ratio = qreal(vertical?option->rect.height():option->rect.width())/maximum; - const int progress = pbar->progress*ratio; + const auto totalSteps = qint64(pbar->maximum) - pbar->minimum; + const auto progressSteps = qint64(pbar->progress) - pbar->minimum; + const auto availablePixels = vertical ? option->rect.height() : option->rect.width(); + const auto pixelsPerStep = double(availablePixels) / totalSteps; + + const auto progress = static_cast(progressSteps * pixelsPerStep); // width in pixels QRect optRect = option->rect; if (vertical) { -- cgit v1.2.3