How can I detect whether a double click on a QWidget (QStatusBar, in my case) occured while a modifier key was held down?
I can开发者_如何转开发 overload void QWidget::mouseDoubleClickEvent ( QMouseEvent * event )
to get the double click, but how can I sure whether the widget receives the key events when it might not have the focus?
I found the answer:
QMouseEvent
is derived from QInputEvent
and that has a method called modifiers()
:
From the Qt documentation:
Returns the keyboard modifier flags that existed immediately before the event occurred.
If you have a SLOT for your (Mouse)Event or Signal, you can test the modifiers there:
Qt::KeyboardModifiers modifiers = QApplication::queryKeyboardModifiers ();
if(modifiers.testFlag( Qt::ControlModifier )){
qDebug() << "CTRL was hold when this function was called";
}
else{
qDebug() << "CTRL wasn't hold";
}
//SHIFT = Qt::ShiftModifier
//CTRL = Qt::ControlModifier
//ALT = Qt::AltModifier
Just to add More information in your QWidget you only need to override this method
protected:
void mouseDoubleClickEvent(QMouseEvent *event);
cheers
精彩评论