Disable Slider Click
-
I am looking for the way where I can customize the slider so that the only way to change the value is using the slider thumb. I want to get rid of the slider functionality, where slider value can be changed by just clicking on the slider bar.
-
Subclass the QSlider and reimplement the mousePressEvent().
-
thanks, but how do I track if the mouse is pressed on the thumb or it is on the slider bar?
-
Note: I'm guessing based on how I would implement it.
The thumb is probably a separate widget and has it's own mouse press events. I could be wrong though. Best course of action is to inspect the source of QSlider here and find out what exactly needs to be done. You could also try and find out by subclassing, reimplementing mousePressEvent to do nothing at all and see what happens. If that does what you need, you don't need to go into the source after all.
-
I am not sure if thumb is a separate widget. Can i cast the sender object into QWidget and check its type?
-
I might be wrong of course :).
You can even check it's type without casting it to QWidget. It's a QObject after all.
-
I think you have to subclass it and overwrite mouseEvents. Have a look at the Qt sources, afaik the slider thumb is only painted and no real object. look at the implementation of QSlider and see what they have done, then change yours according to it.