Swipe gesture in Android not working?

  • I am trying to make a application and I am trying out gestures, the funny thing is that Swipe gesture doesn't do anything. I made a basic new Qt MainWindow application with the following

    @MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    bool MainWindow::event(QEvent event){
    if (event->type() == QEvent::Gesture)
    return gestureEvent(static_cast<QGestureEvent
    return QWidget::event(event);

    bool MainWindow::gestureEvent(QGestureEvent *event){
    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
    swipeT(static_cast<QSwipeGesture *>(swipe));
    // commented out the tap gesture to check if tap and hold gesture works properly
    /if(QGesture tap=event->gesture(Qt::TapGesture))
    if(QGesture tapnh=event->gesture(Qt::TapAndHoldGesture))
    return true;

    void MainWindow::tapNH(QTapAndHoldGesture *gesture){
    QMessageBox::information(this,"Tap and Hold", "Merge");

    void MainWindow::tapG(QTapGesture *gesture){
    QMessageBox::information(this,"Tap","Tap merge");

    void MainWindow::swipeT(QSwipeGesture *gesture){
    if (gesture->state() == Qt::GestureFinished) {
    //comented out direction to check if it is the direction that's causing the problem
    /if (gesture->horizontalDirection() == QSwipeGesture::Left) {
    else if(gesture->horizontalDirection()==QSwipeGesture::Right){

    I am testing it on a Android 2.3 tablet....and it has a multi touch screen.
    Using Qt 5.2.1 for Android, working on Ubuntu 14.04.

    Someone said on a post of mine that Qt gestures are a bit buggy, but surely there should be a fix/alternative way of achieving this, seeing how gestures are the main ways of navigating on a tablet/smartphone, can someone help me/point me in the right direction?

  • Moderators

    If you want gestures just to scroll some widgets, the easiest way is to use QScroller. All it requires is to add a single line to your code :-)

  • I will try your solution, thank you, though I will want to use swipe gesture to swipe through a series of widgets.

  • Moderators

    Much easier to use QtQuick module, then. But the QScroller sollution should still work, if you put your screens in a QScrollArea.

  • Thank you for your guidance.

Log in to reply

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