PDA

View Full Version : QDial value wrapping restriction.



dheeraj.chitrapur
21st November 2013, 09:56
Hi All,

I'm using QDial and I have used setWrapping(false) function to restrict the QDial movement beyond max/min position. But still the QDial wraps to minimum after dragging beyond maximum range of QDial.

Is there any way to restrict the QDial so that it stays in maximum/minimum position?

Any help in solving this issue is really appreciated.

Thanks,
Dheeraj

stampede
21st November 2013, 16:33
You can connect to actionTriggered(int) signal and prevent moving the slider to new value when current value is minimum() or maximum(), and new value seems to be "wrapped". Watch for QAbstractSlider::SliderMove action:


class NoWrapDial : public QDial{
Q_OBJECT
public:
NoWrapDial(QWidget * parent = NULL) : QDial(parent)
{
connect(this, SIGNAL(actionTriggered(int)), this, SLOT(onAction(int)));
}
protected slots:
void onAction(int val){
static const int minDistance = 1;
if (val == QAbstractSlider::SliderMove) {
if (value() == maximum() && sliderPosition()<maximum()-minDistance) {
this->setSliderPosition(maximum());
} else if (value() == minimum() && sliderPosition()>minimum()+minDistance){
this->setSliderPosition(minimum());
}
}
}
};


btw. this requires tracking to be enabled (the default)