diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-16 15:58:57 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-09-17 14:16:30 +0200 |
commit | 96d2f717362c8d79d9eaf7e5cc2cb54e61d997e1 (patch) | |
tree | a674525075a58d435f657111540c8c7821459e67 /src/imports/nativestyle/items | |
parent | e5827955cfae9928d4d0213b7db51f72fd765562 (diff) |
Native style: support progressbars with a range from 0 - 1
A ProgressBar is based on floating point numbers, meaning that
it can have e.g from == 0.5, to == 1.5, and value == 0.8.
A ProgressBar in QStyle on the other hand is integer-based. So
add some extra code to convert floats to ints before passing
the values to QStyle. But only do this for ranges smaller than
100, to ensure that we don't overflow ranges that are really large.
And let "to" start at 0 in case the range ends close to Number.MAX_VALUE.
Change-Id: I2707647911ee31c91b435697d4ae840b304c5c69
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp index 9c393d9f..707b9c62 100644 --- a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp +++ b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp @@ -101,6 +101,11 @@ void QQuickStyleItemProgressBar::initStyleOption(QStyleOptionProgressBar &styleO if (progressBar->isIndeterminate()) { styleOption.minimum = 0; styleOption.maximum = 0; + } else if (progressBar->to() - progressBar->from() < 100) { + // Add some range to support float numbers + styleOption.minimum = 0; + styleOption.maximum = (progressBar->to() - progressBar->from()) * 100; + styleOption.progress = (progressBar->value() - progressBar->from()) * 100; } else { styleOption.minimum = progressBar->from(); styleOption.maximum = progressBar->to(); |