QSlider: show bar from center +/-
-
Hello,
Sorry if this has been asked/answered, I could not find it. I would like to use a slider which goes from -100 to 100. By default, the blue bar is drawn from the leftmost corner, i.e. from -100 to the given value. How can it be changed so that the blue bar is drawn between the central value (0) and the actual value?
Thank you
Daniel -
@daniel-barna said in QSlider: show bar from center +/-:
How can it be changed so that the blue bar is drawn between the central value (0) and the actual value?
slider->setRange(-100, 100); slider->setValue(0);
This meets your requirements, but it is probably not what you are looking for...
For custom style and behavior, you have to write your own slider widgetEdit:
You have this:
|-----|-----|-----|-----|-----|-----|
^
and want this?
|-----|-----|-----|-----|-----|-----|
^
the blue bar is drawn from the leftmost corner, i.e. from -100 to the given value
You must be on MacOS then, right?!
Could be an OS specific thing. I dont know how sliders are natively drawn on macOS but probably the bar starts at the origin. So for your goal you would need to move the origin to the center of your scale and go from there (left for negative values, right for positive).