Search code examples
qt

Qt progress bar - display double value


I have to show the instantaneous value of a sensor output using a QProgressbar.

value can change from 0 to 0.3

how do I configure (set range and set value) the QProgressBar to display the above value.

I'm a bit confused because setRange method can only take int values, and how do I set range as 0 and 0.3?


Solution

  • There are different way. You can chose between these two options:
    Transform your range in an integer range by multiplying by 100

    [0 , 0.3] -> [0 , 300]
    When you receive a new value, just multiply it by 100 0.12*100 = 120/300


    You can also make setRange(0, 100) and for each value, make the conversion:

    (value * maxValue) / 100
    So (0.12 / 0.3) * 100 give you 40%