Just yesterday a team mate asked me how to fake a gesture event on a desktop, say by clicking on a button, and I quickly wrote this example using Qt Designer form, a push button when clicked sends a tap gesture. Comments welcome :)
PS. Just remember: Gesture objects are not constructed directly by developers. They are created by the QGestureRecognizer object that is registered with the application; see QGestureRecognizer::registerRecognizer().
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QDebug>
- #include <QTapGesture>
- #include <QGestureEvent>
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(gest()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::gest()
- {
- QTapGesture *tapGes = new QTapGesture(this);
- tapGesTureList.append(tapGes);
- QGestureEvent event(tapGesTureList);
- }
- {
- {
- QGestureEvent *gestevent = static_cast<QGestureEvent*>(event);
- {
- QTapGesture *tapgest = static_cast<QTapGesture *>(gest);
- qDebug() << "tap gesture got at: " << tapgest->position();
- }
- }
- return true;
- }

