Passing touch coordinates to qml



  • Hi, another problem that I'm facing and where I might need some help:

    I have a parser class in C++ in which I receive coordinates from a touch device every ~15ms. Now here's the big question: is it possible to pass those coordinates directly to qml without any additional parsing? I just want to move a Rectangle around on the screen, so no big rocket science.



  • If you expose the parser class to QML (ie, make it a QObject and expose the touchX and touchY coordinates as Q_PROPERTY ints) then you can simply bind the rectangle's x/y properties to the parser's touchX and touchY coordinates.

    If you don't want to expose the parser class, you could update context properties, but that will cause all bindings (not just the ones involving those properties) to be re-evaluated on every update, and so will most likely cause a prohibitive performance penalty.

    The final thing you could do is create a mouse click event from the touch coordinates, and send the event to a MouseArea defined in QML - its onClicked signal-handler could manually position the rectangle according to the mouse.x and mouse.y values available in the handler. But this is something I haven't ever tried, so YMMV.

    Cheers,
    Chris.


Log in to reply
 

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