PDA

View Full Version : Resetting a QSlider with double click



Cruz
15th May 2011, 22:02
Hello!

I have several QSliders scattered around on a quite complex GUI. All of them should be able to reset to 0 when double clicked. Unfortunately QSliders don't have a doubleClicked() signal that I connect to some slot. So what's the best way to implement this?

Thanks
Cruz

Lykurg
15th May 2011, 22:19
QSlider is a QWidget, thus you can use QWidget::mouseDoubleClickEvent(). Simple subclass something like
class MySlider : public QSlider
{
protected:
void mouseDoubleClickEvent(QMouseEvent *event);
}

MySlider::mouseDoubleClickEvent(QMouseEvent *event)
{
setValue(0);
QSlider::mouseDoubleClickEvent(QMouseEvent *event);
}

Or install an event filter.