Important: Please read the Qt Code of Conduct -

Can't catch TapAndHoldGesture

  • I grabGesture()ed one of my buttons:


    in the constructor, and declared:

    bool event(QEvent *event);

    in protected slots, and implemented it like this:

    bool MyClass::event(QEvent *event)
        if (event->type() == QEvent::Gesture){
            QGestureEvent *gestevent = static_cast<QGestureEvent *>(event);
            if (QGesture *gest = gestevent->gesture(Qt::TapAndHoldGesture)){
                QTapAndHoldGesture *tapgest = static_cast<QTapAndHoldGesture *>(gestevent->gesture(Qt::TapAndHoldGesture));
                cout << "grabbed a gesture event" << endl;
            return true;
        cout << "not a gesture event" << endl;
        return QWidget::event(event);

    and I keep getting "not a gesture event" printed to screen.

    What I'm trying to do is a long key press (from the keyboard)

Log in to reply