PDA

View Full Version : QSlider



ToddAtWSU
10th May 2006, 13:22
Is it possible to click anywhere on a QSlider bar and move the actual slider part to that point on the bar? Instead of dragging the slider to the desired location, just click on the desired location and move the slider to that spot? If this is possible what signal do I need to watch for or what else do I need to do? I cannot find anything that appears as if this idea will work. Thanks!

e8johan
10th May 2006, 13:45
To me, it sounds as if you will have to sub-class a slider and re-implement the mousePress or mouseRelease event handlers.

ToddAtWSU
10th May 2006, 16:28
But if I would re-implement those functions, then I would probably lose my capabilities to grab the slider and move it up and down the bar, right? Thanks again!

jpn
10th May 2006, 16:41
But if I would re-implement those functions, then I would probably lose my capabilities to grab the slider and move it up and down the bar, right?
You can, of course, call base class implementation if you want to. So you don't have to re-implement the whole event, you can just add some little tricks of your own and then let the base class handle the rest.

I'd say, all you need to do is to override mouse press event; set the slider to the corresponding position, and then call base class implementation.

And if you're wondering how to change the slider's value corresponding to the mouse position, check QSliderPrivate::pixelPosToRangeValue() in src/gui/widgets/qslider.cpp.