summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-01-05 08:10:53 +0100
committerMarc Mutz <marc.mutz@kdab.com>2017-01-07 10:48:45 +0000
commit1d1b60dee40de3b8d67be46399b58d4b1ecddab1 (patch)
tree76a13a6a21c703c096af46666b60fd9fe987a469 /src/widgets
parent555a0f3c511368eff51cd0f8e52f0abc7a0ff28c (diff)
QStylesheetStyle: don't lose precision when drawing a progress bar
When qreal is float, it cannot represent all values an int can take, so we may lose precision in the expression qreal(a) / b as opposed to the double result double(a) / b For lack of trying, I do not know of a value where this would change the resulting 'fillWidth' value, but better be safe than sorry, and use double instead of qreal arithmetic. Also, when calculating fillRatio, we were converting values back and forth between qreal and double. Using double everywhere avoids that. Found while reviewing integer arithmetic in QProgressBar as part of the fix for QTBUG-57857. Change-Id: I054cb11d35e3ecf5bf79b5c8ee39029bd23bcf49 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index d63c96bf0e..68ee8c22d3 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -3903,8 +3903,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
if (inverted)
reverse = !reverse;
const bool indeterminate = pb->minimum == pb->maximum;
- qreal fillRatio = indeterminate ? 0.50 : qreal(progress - minimum)/(maximum - minimum);
- int fillWidth = int(rect.width() * fillRatio);
+ const auto fillRatio = indeterminate ? 0.50 : double(progress - minimum) / (maximum - minimum);
+ const auto fillWidth = static_cast<int>(rect.width() * fillRatio);
int chunkWidth = fillWidth;
if (subRule.hasContentsSize()) {
QSize sz = subRule.size();