May 14, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

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

  1. QList<QTouchEvent::TouchPoint> touchPoints;
  2.  
  3. QTouchEvent::TouchPoint p(1); // the hardcoded touch id is just for testing
  4. p.setState(Qt::TouchPointMoved);
  5. p.setScenePos(QPointF(pt.x, pt.y)); // pt is a simple point structure
  6. p.setPressure(1);
  7. touchPoints.append(p);
  8.  
  9. QTouchEvent touchEvent(QEvent::TouchUpdate, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointMoved, touchPoints);
  10. QCoreApplication::sendEvent(my_qmlApplicationViewer->scene(), &touchEvent);

and also set

  1. setAttribute(Qt::WA_AcceptTouchEvents);
  2. 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

1 reply

May 21, 2012

alexleutgoeb alexleutgoeb
Lab Rat
29 posts

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.

 
  ‹‹ Is it possible to use qDeclarativeView in QtQuick 2.0      [SOLVED] listview with 2 models and back button ››

You must log in to post a reply. Not a member yet? Register here!