Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Swipe gesture in Android not working?

Swipe gesture in Android not working?

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adutzu89
    wrote on last edited by
    #1

    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) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    grabGesture(Qt::SwipeGesture);
    grabGesture(Qt::TapGesture);
    grabGesture(Qt::TapAndHoldGesture);
    }

    bool MainWindow::event(QEvent event){
    if (event->type() == QEvent::Gesture)
    return gestureEvent(static_cast<QGestureEvent
    >(event));
    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))
    tapG(static_cast<QTapGesture
    >(tap));
    /
    if(QGesture tapnh=event->gesture(Qt::TapAndHoldGesture))
    tapNH(static_cast<QTapAndHoldGesture
    >(tapnh));
    return true;
    }

    void MainWindow::tapNH(QTapAndHoldGesture *gesture){
    if(gesture->state()==Qt::GestureFinished)
    QMessageBox::information(this,"Tap and Hold", "Merge");
    }

    void MainWindow::tapG(QTapGesture *gesture){
    if(gesture->state()==Qt::GestureFinished)
    QMessageBox::information(this,"Tap","Tap merge");
    }

    void MainWindow::swipeT(QSwipeGesture *gesture){
    if (gesture->state() == Qt::GestureFinished) {
    QMessageBox::information(this,"Swipe","Merge");
    //comented out direction to check if it is the direction that's causing the problem
    /if (gesture->horizontalDirection() == QSwipeGesture::Left) {
    QMessageBox::information(this,"Swipe","Stanga");
    }
    else if(gesture->horizontalDirection()==QSwipeGesture::Right){
    QMessageBox::information(this,"Swipe","dreapta");
    }
    /
    }
    }@

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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 :-)

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adutzu89
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            adutzu89
            wrote on last edited by
            #5

            Thank you for your guidance.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved