Simulating touchevents for QML



  • Hi all,

    I'm currently trying to simulate some touch events which should be processed in a MouseArea item in QML. I create and send my touch events like

    @QListQTouchEvent::TouchPoint touchPoints;

    QTouchEvent::TouchPoint p(1); // the hardcoded touch id is just for testing
    p.setState(Qt::TouchPointMoved);
    p.setScenePos(QPointF(pt.x, pt.y)); // pt is a simple point structure
    p.setPressure(1);
    touchPoints.append(p);

    QTouchEvent touchEvent(QEvent::TouchUpdate, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointMoved, touchPoints);
    QCoreApplication::sendEvent(my_qmlApplicationViewer->scene(), &touchEvent);@

    and also set

    @setAttribute(Qt::WA_AcceptTouchEvents);
    viewport()->setAttribute(Qt::WA_AcceptTouchEvents);@

    in a QmlApplicationViewer subclass' constructor, however the touches never get forwarded into QML code.

    Am I something (touch-related) missing?

    Thx,
    Alex



  • I finally figured it out, the touch events are not converted to click events in the GraphicsScene so I'm sending the click events manually too. The PinchArea however does receive my custom touch events, so the code is conceptually correct.


Log in to reply
 

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