Hi all.
Is there a way to simulate a pinch gesture on a PinchArea?

I tried to simulate it by sending QTouchEvent events as follows (the given parameter is a pointer to a PinchArea item):
Qt Code:
  1. void BackendItem1::pinch1(QQuickItem* item)
  2. {
  3. QList<QTouchEvent::TouchPoint> points1;
  4. QTouchEvent::TouchPoint p1;
  5. p1.setPos(QPointF(10, 10));
  6. p1.setStartPos(QPointF(10, 10));
  7. p1.setPressure(0.5);
  8. p1.setId(1);
  9.  
  10. QTouchEvent::TouchPoint p2;
  11. p2.setPos(QPointF(310, 310));
  12. p2.setStartPos(QPointF(310, 310));
  13. p2.setPressure(0.5);
  14. p2.setId(2);
  15.  
  16. points1 << p1 << p2;
  17.  
  18. QTouchEvent te1(QEvent::TouchBegin, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointPressed, points1);
  19. QCoreApplication::sendEvent(item, &te1);
  20.  
  21. p1.setLastPos(p1.pos());
  22. p2.setLastPos(p2.pos());
  23. p1.setPos(QPointF(60, 60));
  24. p2.setPos(QPointF(260, 260));
  25. points1.clear();
  26. points1 << p1 << p2;
  27. QTouchEvent te2(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
  28. QCoreApplication::sendEvent(item, &te2);
  29.  
  30. p1.setLastPos(p1.pos());
  31. p2.setLastPos(p2.pos());
  32. p1.setPos(QPointF(110, 110));
  33. p2.setPos(QPointF(210, 210));
  34. points1.clear();
  35. points1 << p1 << p2;
  36. QTouchEvent te3(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
  37. QCoreApplication::sendEvent(item, &te3);
  38.  
  39. p1.setLastPos(p1.pos());
  40. p2.setLastPos(p2.pos());
  41. p1.setPos(QPointF(110, 110));
  42. p2.setPos(QPointF(210, 210));
  43. points1.clear();
  44. points1 << p1 << p2;
  45. QTouchEvent te4(QEvent::TouchEnd, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointReleased, points1);
  46. QCoreApplication::sendEvent(item, &te4);
  47. }
To copy to clipboard, switch view to plain text mode 

or (in the second try I tried to create a QTouchDevice instead of sending Q_NULLPTR):
Qt Code:
  1. void BackendItem1::pinch3(QQuickItem* item)
  2. {
  3. QTouchDevice td1;
  4. td1.setMaximumTouchPoints(5);
  5. td1.setType(QTouchDevice::TouchScreen);
  6.  
  7. QList<QTouchEvent::TouchPoint> points1;
  8. QTouchEvent::TouchPoint p1;
  9. p1.setPos(QPointF(10, 10));
  10. p1.setStartPos(QPointF(10, 10));
  11. p1.setPressure(0.5);
  12. p1.setId(1);
  13.  
  14. QTouchEvent::TouchPoint p2;
  15. p2.setPos(QPointF(310, 310));
  16. p2.setStartPos(QPointF(310, 310));
  17. p2.setPressure(0.5);
  18. p2.setId(2);
  19.  
  20. points1 << p1 << p2;
  21.  
  22. QTouchEvent te1(QEvent::TouchBegin, &td1, Qt::NoModifier, Qt::TouchPointPressed, points1);
  23. QCoreApplication::sendEvent(item, &te1);
  24.  
  25. p1.setLastPos(p1.pos());
  26. p2.setLastPos(p2.pos());
  27. p1.setPos(QPointF(60, 60));
  28. p2.setPos(QPointF(260, 260));
  29. points1.clear();
  30. points1 << p1 << p2;
  31. QTouchEvent te2(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
  32. QCoreApplication::sendEvent(item, &te2);
  33.  
  34. p1.setLastPos(p1.pos());
  35. p2.setLastPos(p2.pos());
  36. p1.setPos(QPointF(110, 110));
  37. p2.setPos(QPointF(210, 210));
  38. points1.clear();
  39. points1 << p1 << p2;
  40. QTouchEvent te3(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
  41. QCoreApplication::sendEvent(item, &te3);
  42.  
  43. p1.setLastPos(p1.pos());
  44. p2.setLastPos(p2.pos());
  45. p1.setPos(QPointF(110, 110));
  46. p2.setPos(QPointF(210, 210));
  47. points1.clear();
  48. points1 << p1 << p2;
  49. QTouchEvent te4(QEvent::TouchEnd, &td1, Qt::NoModifier, Qt::TouchPointReleased, points1);
  50. QCoreApplication::sendEvent(item, &te4);
  51. }
To copy to clipboard, switch view to plain text mode 

I also tried to do that using a QNativeGestureEvent event as follows:
Qt Code:
  1. void BackendItem1::pinch2(QQuickItem* item)
  2. {
  3. QNativeGestureEvent nge0(Qt::BeginNativeGesture, QPointF(200,200),
  4. QPointF(202,202), QPointF(202,202), 1,1,1);
  5. QCoreApplication::sendEvent(item, &nge0);
  6.  
  7. QNativeGestureEvent nge1(Qt::ZoomNativeGesture, QPointF(200,200),
  8. QPointF(202,202), QPointF(202,202), 0.9,2,1);
  9. QCoreApplication::sendEvent(item, &nge1);
  10.  
  11. QNativeGestureEvent nge2(Qt::ZoomNativeGesture, QPointF(200,200),
  12. QPointF(202,202), QPointF(202,202), 0.8,3,1);
  13. QCoreApplication::sendEvent(item, &nge2);
  14.  
  15. QNativeGestureEvent nge3(Qt::EndNativeGesture, QPointF(200,200),
  16. QPointF(202,202), QPointF(202,202), 0.8,4,1);
  17. QCoreApplication::sendEvent(item, &nge3);
  18. }
To copy to clipboard, switch view to plain text mode 

But, none of my tries gave me any success (It looks like nothing happens in the PinchArea).

Any idea?