February 10, 2011

NDev NDev
Lab Rat
9 posts

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.

6 replies

February 10, 2011

Franzk Franzk
Lab Rat
830 posts

Subclass the QSlider and reimplement the mousePressEvent().

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

February 10, 2011

NDev NDev
Lab Rat
9 posts

thanks, but how do I track if the mouse is pressed on the thumb or it is on the slider bar?

February 10, 2011

Franzk Franzk
Lab Rat
830 posts

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.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

February 16, 2011

NDev NDev
Lab Rat
9 posts

I am not sure if thumb is a separate widget. Can i cast the sender object into QWidget and check its type?

February 16, 2011

Franzk Franzk
Lab Rat
830 posts

I might be wrong of course :).

You can even check it’s type without casting it to QWidget. It’s a QObject after all.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

February 16, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

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.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ PDF specification used for PDF files generated by QPrintDialog      Spinbox StyleSheet Margin create background shift :S ››

You must log in to post a reply. Not a member yet? Register here!