Android App Swipe Gesture : How to



  • Hi, I'm coding an app for android. I would like to know how to catch a swipe left or right gesture event.

    Thank You,
    Charles


  • Moderators

    @thinkpad_32167 said in Android App Swipe Gesture : How to:

    I would like to know how to catch a swipe left or right gesture event.

    use the forum search or google search.
    I am pretty sure you will find such a simple answer out by your own...



  • I have tried a few examples I found on google but without success. I think I have a problem differentiating the stylus events from the touch events. Here is the code :

    bool TabletApplication::event(QEvent *event)
    {

    if (event->type() == QEvent::TabletEnterProximity ||
        event->type() == QEvent::TabletLeaveProximity) {
        m_canvas->setTabletDevice(static_cast<QTabletEvent *>(event));
        return true;
    }
    
    if(event->type() ==  QEvent::Gesture){
        QMessageBox::information(main_window, "Test Message",
                                 "swipe triggered");
        return gestureEvent(static_cast<QGestureEvent*>(event));
    }
    if(event->type() ==  QEvent::Gesture){
        QMessageBox::information(main_window, "Test Message",
                                 "swipe triggered");
        return gestureEvent(static_cast<QGestureEvent*>(event));
    }
    return QApplication::event(event);
    

    }

    bool TabletApplication::gestureEvent(QGestureEvent *event)
    {

    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
        swipeTriggered(static_cast<QSwipeGesture *>(swipe));
    /*
    else if (QGesture *pan = event->gesture(Qt::PanGesture))
        panTriggered(static_cast<QPanGesture *>(pan));
    if (QGesture *pinch = event->gesture(Qt::PinchGesture))
        pinchTriggered(static_cast<QPinchGesture *>(pinch));
        */
    return true;
    

    }

    void TabletApplication::swipeTriggered(QSwipeGesture *gesture)
    {

    if (gesture->state() == Qt::GestureFinished) {
        if (gesture->horizontalDirection() == QSwipeGesture::Left
            || gesture->verticalDirection() == QSwipeGesture::Up) {
            main_window->showPreviousWeek();
    
        } else {
            main_window->showNextWeek();
        }
        main_window->update();
    }
    

    }

    Thank you for your help


  • Moderators

    @thinkpad_32167
    i apologize. I assumed you are using QML.
    For QtWidgets you need to call QWidget::grabGesture() toll gefunden für Texture events


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.