I know that, but using mouseReleaseEvent wont help you either - before you receive mouseDoubleClickEvent there will be mousePressEvent and mouseReleaseEvent (and another "press" and "release" after double click). So my previous suggestion is stupid.
What about using the timer, something like this:
Q_OBJECT
public:
_timer.setInterval(200);
_timer.setSingleShot(true);
connect(&_timer, SIGNAL(timeout()), this, SLOT(timeout()));
_doubleClicked = false;
}
protected slots:
void timeout(){
// do the stuff for single click() here
qDebug() << "single click";
}
protected:
if( _doubleClicked ){
_doubleClicked = false;
} else{
_timer.start();
}
}
_timer.stop();
_doubleClicked = true; // this is to discard another press event coming
qDebug() << "double click";
QWidget::mouseDoubleClickEvent(ev
);
}
private:
bool _doubleClicked;
};
class Widget : public QWidget{
Q_OBJECT
public:
Widget( QWidget * parent = NULL ) : QWidget(parent){
_timer.setInterval(200);
_timer.setSingleShot(true);
connect(&_timer, SIGNAL(timeout()), this, SLOT(timeout()));
_doubleClicked = false;
}
protected slots:
void timeout(){
// do the stuff for single click() here
qDebug() << "single click";
}
protected:
void mousePressEvent( QMouseEvent * ev ){
if( _doubleClicked ){
_doubleClicked = false;
} else{
_timer.start();
}
QWidget::mousePressEvent(ev);
}
void mouseDoubleClickEvent( QMouseEvent * ev ){
_timer.stop();
_doubleClicked = true; // this is to discard another press event coming
qDebug() << "double click";
QWidget::mouseDoubleClickEvent(ev);
}
private:
QTimer _timer;
bool _doubleClicked;
};
To copy to clipboard, switch view to plain text mode
Bookmarks