sz
9th May 2016, 14:40
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):
void BackendItem1::pinch1(QQuickItem* item)
{
QList<QTouchEvent::TouchPoint> points1;
QTouchEvent::TouchPoint p1;
p1.setPos(QPointF(10, 10));
p1.setStartPos(QPointF(10, 10));
p1.setPressure(0.5);
p1.setId(1);
QTouchEvent::TouchPoint p2;
p2.setPos(QPointF(310, 310));
p2.setStartPos(QPointF(310, 310));
p2.setPressure(0.5);
p2.setId(2);
points1 << p1 << p2;
QTouchEvent te1(QEvent::TouchBegin, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointPressed, points1);
QCoreApplication::sendEvent(item, &te1);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(60, 60));
p2.setPos(QPointF(260, 260));
points1.clear();
points1 << p1 << p2;
QTouchEvent te2(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te2);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te3(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te3);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te4(QEvent::TouchEnd, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointReleased, points1);
QCoreApplication::sendEvent(item, &te4);
}
or (in the second try I tried to create a QTouchDevice instead of sending Q_NULLPTR):
void BackendItem1::pinch3(QQuickItem* item)
{
QTouchDevice td1;
td1.setMaximumTouchPoints(5);
td1.setType(QTouchDevice::TouchScreen);
QList<QTouchEvent::TouchPoint> points1;
QTouchEvent::TouchPoint p1;
p1.setPos(QPointF(10, 10));
p1.setStartPos(QPointF(10, 10));
p1.setPressure(0.5);
p1.setId(1);
QTouchEvent::TouchPoint p2;
p2.setPos(QPointF(310, 310));
p2.setStartPos(QPointF(310, 310));
p2.setPressure(0.5);
p2.setId(2);
points1 << p1 << p2;
QTouchEvent te1(QEvent::TouchBegin, &td1, Qt::NoModifier, Qt::TouchPointPressed, points1);
QCoreApplication::sendEvent(item, &te1);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(60, 60));
p2.setPos(QPointF(260, 260));
points1.clear();
points1 << p1 << p2;
QTouchEvent te2(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te2);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te3(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te3);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te4(QEvent::TouchEnd, &td1, Qt::NoModifier, Qt::TouchPointReleased, points1);
QCoreApplication::sendEvent(item, &te4);
}
I also tried to do that using a QNativeGestureEvent event as follows:
void BackendItem1::pinch2(QQuickItem* item)
{
QNativeGestureEvent nge0(Qt::BeginNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 1,1,1);
QCoreApplication::sendEvent(item, &nge0);
QNativeGestureEvent nge1(Qt::ZoomNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.9,2,1);
QCoreApplication::sendEvent(item, &nge1);
QNativeGestureEvent nge2(Qt::ZoomNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.8,3,1);
QCoreApplication::sendEvent(item, &nge2);
QNativeGestureEvent nge3(Qt::EndNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.8,4,1);
QCoreApplication::sendEvent(item, &nge3);
}
But, none of my tries gave me any success (It looks like nothing happens in the PinchArea).
Any idea?
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):
void BackendItem1::pinch1(QQuickItem* item)
{
QList<QTouchEvent::TouchPoint> points1;
QTouchEvent::TouchPoint p1;
p1.setPos(QPointF(10, 10));
p1.setStartPos(QPointF(10, 10));
p1.setPressure(0.5);
p1.setId(1);
QTouchEvent::TouchPoint p2;
p2.setPos(QPointF(310, 310));
p2.setStartPos(QPointF(310, 310));
p2.setPressure(0.5);
p2.setId(2);
points1 << p1 << p2;
QTouchEvent te1(QEvent::TouchBegin, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointPressed, points1);
QCoreApplication::sendEvent(item, &te1);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(60, 60));
p2.setPos(QPointF(260, 260));
points1.clear();
points1 << p1 << p2;
QTouchEvent te2(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te2);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te3(QEvent::TouchUpdate, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te3);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te4(QEvent::TouchEnd, Q_NULLPTR, Qt::NoModifier, Qt::TouchPointReleased, points1);
QCoreApplication::sendEvent(item, &te4);
}
or (in the second try I tried to create a QTouchDevice instead of sending Q_NULLPTR):
void BackendItem1::pinch3(QQuickItem* item)
{
QTouchDevice td1;
td1.setMaximumTouchPoints(5);
td1.setType(QTouchDevice::TouchScreen);
QList<QTouchEvent::TouchPoint> points1;
QTouchEvent::TouchPoint p1;
p1.setPos(QPointF(10, 10));
p1.setStartPos(QPointF(10, 10));
p1.setPressure(0.5);
p1.setId(1);
QTouchEvent::TouchPoint p2;
p2.setPos(QPointF(310, 310));
p2.setStartPos(QPointF(310, 310));
p2.setPressure(0.5);
p2.setId(2);
points1 << p1 << p2;
QTouchEvent te1(QEvent::TouchBegin, &td1, Qt::NoModifier, Qt::TouchPointPressed, points1);
QCoreApplication::sendEvent(item, &te1);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(60, 60));
p2.setPos(QPointF(260, 260));
points1.clear();
points1 << p1 << p2;
QTouchEvent te2(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te2);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te3(QEvent::TouchUpdate, &td1, Qt::NoModifier, Qt::TouchPointMoved, points1);
QCoreApplication::sendEvent(item, &te3);
p1.setLastPos(p1.pos());
p2.setLastPos(p2.pos());
p1.setPos(QPointF(110, 110));
p2.setPos(QPointF(210, 210));
points1.clear();
points1 << p1 << p2;
QTouchEvent te4(QEvent::TouchEnd, &td1, Qt::NoModifier, Qt::TouchPointReleased, points1);
QCoreApplication::sendEvent(item, &te4);
}
I also tried to do that using a QNativeGestureEvent event as follows:
void BackendItem1::pinch2(QQuickItem* item)
{
QNativeGestureEvent nge0(Qt::BeginNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 1,1,1);
QCoreApplication::sendEvent(item, &nge0);
QNativeGestureEvent nge1(Qt::ZoomNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.9,2,1);
QCoreApplication::sendEvent(item, &nge1);
QNativeGestureEvent nge2(Qt::ZoomNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.8,3,1);
QCoreApplication::sendEvent(item, &nge2);
QNativeGestureEvent nge3(Qt::EndNativeGesture, QPointF(200,200),
QPointF(202,202), QPointF(202,202), 0.8,4,1);
QCoreApplication::sendEvent(item, &nge3);
}
But, none of my tries gave me any success (It looks like nothing happens in the PinchArea).
Any idea?