PDA

View Full Version : QSlider how to check if slider handle is selected



hel
14th May 2014, 06:56
Hi,

I am trying to get the slider handle to move only when it is selected and drag. I have subclass the QSlider class , re-implementing the mousePressEvent function.

In my mousePressEvent function.


Q_D(QSlider);
if (d->pressedControl != QStyle::SC_SliderHandle)

I am unable to access d_func() as it is private , is there any work around so i am able to check if the selected object is the slider handle?

high_flyer
14th May 2014, 09:28
Why are you going so low level?
Why not just use sliderPressed() signal?
Or even better, sliderMoved()?
http://qt-project.org/doc/qt-4.8/qabstractslider.html#sliderMoved

anda_skoa
14th May 2014, 09:32
I don't think you can do that in a subclass.

What you could try it so overwrite sliderChange() and check for value changes.
If the slider is pressed at the time you allow it to pass, if not, you don't. The latter might require to reset the value

Other options are to modify the slider implementation in your copy of Qt or copy the slider implementation in to a new class and have it in a separate "addon" library

Cheers,
_

high_flyer
15th May 2014, 08:52
I am trying to get the slider handle to move only when it is selected and drag.
but isn't this the normal QSlider behavior?
From the docs for QAbstractSlider::sliderMoved ( int value ):

This signal is emitted when sliderDown is true and the slider moves. This usually happens when the user is dragging the slider. The value is the new slider position.

This signal is emitted even when tracking is turned off.

Otherwise, what exactly do you mean by "selected and drag"?