PDA

View Full Version : qslider fixed to tick marks



holst
24th July 2009, 10:56
Hi,

I need that the Slider moves not to be continous, only from a tick to another ignoring the space (and therefore the values) between the 2 ticks.

I see how create the ticks with setTickPosition() and setTickInterval(), but nothing to fix the slider handle to the ticks.

Any idea?

Lykurg
24th July 2009, 11:34
QSlider slider;
slider.setTickInterval(1);
slider.setRange(0,40); // where 40 is your "tick count"

holst
24th July 2009, 12:12
I see, so the movement from a tick to another always is 1 unit.

For example, for a slider that only can take the values 0->25->50->75->100, I have to create a slider from 0->4 with tickInterval=1, and then multiply the value by 4.


QSlider slider;
slider.setTickInterval(1);
slider.setRange(0,4);
...
int nPercentVal = slider.value() * 4;


So, isn't a way to avoid that multiplication (setting range 0->100) but slider handle only moving through 5 ticks in the slider?

holst
24th July 2009, 12:26
Sorry... I mean


int nPercentVal = slider.value() * 25;


:)

Lykurg
24th July 2009, 13:18
Well, I see no possibility for that. But you can easy subclass QSlider and change the value setter and getter function with a custom factor.