Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top