Coordinate transformation problem with gestures and QGraphicsObject



  • Hello,

    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);
    if (pinch)
    {
    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?


Log in to reply
 

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