Qt 5.3.2 android app not receiving gesture event.
-
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();
}
@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()";
}
}
}
@ -
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.