fawick
fawick

Reputation: 590

Qt: Detect Double-Click with Modkey (Shift, CTRL, etc.)

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?

Upvotes: 3

Views: 3370

Answers (3)

fawick
fawick

Reputation: 590

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.

Upvotes: 2

lx222
lx222

Reputation: 248

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 

Upvotes: 1

fredcrs
fredcrs

Reputation: 3621

Just to add More information in your QWidget you only need to override this method

protected:
    void mouseDoubleClickEvent(QMouseEvent *event);

cheers

Upvotes: 0

Related Questions