Configurable QSlider/QDial that uses double values
-
What I'm looking for is a configurable, extensible way to use QSliders and QDials with double values.
I'm aware of the solution involving dividing/multiplying values by a factor of 10, but this is very clunky, unintuitive, and overall confusing. Instead, does there exist a (probably custom) class that has the same functionality as these two slider widgets, but that uses doubles and has a configurable amount of decimal places?
-
@swurl said in Configurable QSlider/QDial that uses double values:
I'm aware of the solution involving dividing/multiplying values by a factor of 10
Why 10?
@swurl said in Configurable QSlider/QDial that uses double values:
this is very clunky, unintuitive, and overall confusing.
It really isn't. Perhaps you could define and refine what you would call "intuitive" and then you would see why.
A slider widget unavoidably operates in discrete values, that is pixels. Integers. Mapping one of these values from an integer range to a double floating point value within another range is trivial maths.
If you need extreme resolution from the UI, set the minimum and maximum values of the slider to match the likely (virtual) pixel dimensions of your UI element, one pixel per slider value, then do the transform from slider value to your floating point range in the valueChanged signal handler.
has a configurable amount of decimal places
That's not up to the slider widget, That's up to the code you write to display the resultant values.
You could generalise this functionality by creating an adaptor class that handles the slider signals, does the numerical range conversions, formats the results as required and signals the values upwards.
-
@KenAppleby-0 said in Configurable QSlider/QDial that uses double values:
It really isn't. Perhaps you could define and refine what you would call "intuitive" and then you would see why.
To implement, that is, but I will try your suggestion to create a customizable class... thank you.