Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Coordinate transformation problem with gestures and QGraphicsObject
mickael.cruz last edited by
I am working on a touchscreen app that displays objects in a QGraphicsScene. I have setup all the event handlers so that mouse and gestures are handled on the proper GraphicsObjects that are in the scene.
However I have a coordinate problem : whenever I use the pinch gesture and to a translation, my object's movement is in another scale that the GraphicsScene.
I tried to transform the gestures coordinate with mapToScene, mapFromScene, mapToParent, mapFromParent without getting it to work. I also tried retrieving the viewport's transform matrix and did the transformation, still without solving my problem.
Here is my code :
void CustomGraphicsObject::gestureEvent(QGestureEvent event)
QGesture pinch = event->gesture(Qt::PinchGesture);
QPinchGesture* pGesture = dynamic_cast<QPinchGesture*>(pinch);
QTransform invViewMatrix = scene()->views().first()->viewportTransform().inverted();
QPointF diffTranslate = invViewMatrix.map(pGesture->centerPoint()) - invViewMatrix.map(pGesture->lastCenterPoint()); emit Gestured(pos() + diffTranslate); setPos(pos() + diffTranslate); }
Does anyone have an idea of what i am doing wrong?