Search code examples
qtmouseeventqtguimodifier-key

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?


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.