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. Qt 5.3.2 android app not receiving gesture event.

Qt 5.3.2 android app not receiving gesture event.

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 1.2k 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.
  • D Offline
    D Offline
    Doc X
    wrote on last edited by
    #1

    I'm just starting the process to move some of my pc touchscreen software to android. I'm creating a very simple program that is supposed to do three things. Draw a black screen, put the time in the lower left corner, and check for a left swipe.

    I used the ImageGestures example as my starting point, but greatly simplified it. When the app starts, I see the message that a swipe gesture event is being grabbed.

    When I swipe, I see "TouchBegins", "TouchUpdate", and "TouchEnd" events, but never a "Gesture" event.

    I've poured over the code, tweaked this and that (adding/subtracting gestures, etc) but have never seen a gesture event. Is there something I'm missing?

    main.cpp
    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainWindow w;
    
    qDebug() << "Welcome to Qt" << QT_VERSION_STR;
    
    QList<Qt::GestureType> gestures;
    gestures << Qt::SwipeGesture;
    
    w.grabGestures(gestures);
    w.show();
    
    return a.exec&#40;&#41;;
    

    }
    @

    mainwindow.cpp
    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    idleWidget(new IdleWidget(this))
    {
    setCentralWidget(idleWidget);
    }

    void MainWindow::grabGestures(const QListQt::GestureType &gestures)
    {
    idleWidget->grabGestures(gestures);
    }
    @

    idlewidget.ccp
    @
    IdleWidget::IdleWidget(QWidget *parent) :
    QWidget(parent)
    {
    }

    void IdleWidget::grabGestures(const QListQt::GestureType &gestures)
    {
    foreach (Qt::GestureType gesture, gestures)
    {
    qDebug() << "grabbing gesture" << gesture;
    grabGesture(gesture);
    }
    }

    void IdleWidget::paintEvent(QPaintEvent *)
    {
    QTime time = QTime::currentTime();
    QString timeNow = time.toString("h:mmap");

    QPainter p(this);
    p.fillRect(0, 0, width(), height(), Qt::black);
    
    p.setPen(QPen(Qt::white));
    p.drawText(QRect(0, 0, width(), height()), Qt::AlignLeft | Qt::AlignBottom, timeNow);
    
    p.end();
    

    }

    bool IdleWidget::event(QEvent *event)
    {
    qDebug() << "event():" << event->type();

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

    }

    bool IdleWidget::gestureEvent(QGestureEvent *event)
    {
    qDebug() << "gestureEvent():" << event->gestures().size();

    if (QGesture *swipe = event->gesture(Qt::SwipeGesture))
        swipeTriggered(static_cast<QSwipeGesture *>(swipe));
    
    return true;
    

    }

    void IdleWidget::swipeTriggered(QSwipeGesture *gesture)
    {
    if (gesture->state() == Qt::GestureFinished)
    {
    if (gesture->horizontalDirection() == QSwipeGesture::Left)
    {
    qDebug() << "LEFT swipeTriggered()";
    }
    }
    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Doc X
      wrote on last edited by
      #2

      Upon further review, my problem was more specific to not receiving swipe events on the android platform. Tap and TapAndHold work, for example.

      What I ended up doing was creating my own swipe gesture recognizer based on this code:

      http://developer.nokia.com/community/wiki/Custom_Swipe_Gestures_in_Qt

      There are a couple of easily fixed bugs in that code, but it seems to work just fine.

      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