Qt: Double-click detection with the Mod key (Shift, CTRL, etc.)

How to determine if there was a double click on a QWidget (QStatusBar, in my case) when the modifier key was held?

I can overload void QWidget::mouseDoubleClickEvent ( QMouseEvent * event )to get a double click, but how can I make sure the widget receives key events when it may not have focus?

+3
source share
3 answers

I found the answer:

QMouseEventobtained from QInputEventand has a method called modifiers():

From the Qt Documentation :

Returns the keyboard modifier flags that existed immediately before the event occurred.

+2
source

SLOT (Mouse) , :

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 
+1

QWidget

protected:
    void mouseDoubleClickEvent(QMouseEvent *event);

0
source

Source: https://habr.com/ru/post/1732545/


All Articles