Important: Please read the Qt Code of Conduct -

Gesture with mouse event problem

  • Hello,

    I'm using Qt 5.3 on Android.
    Problem is that mouseReleaseEvent is not generated for my QGraphicsItem when I'm using two fingers. I can replicate this with such a behaviour: Touch one finger, start swipe, touch second finger (Pinch is started), remove first finger first and then remove second - no mouseReleaseEvent on the item.
    I can see that mousePressEvent is delivered when I press first finger, no event on second finger, so I imagine that if I remove first finger first and then second - the system gets confused.
    I'm using QPinchGesture on QGraphicsView and also mousePress/Move/Release on QGraphicsScene (Can't use QPanGesture becasue it is always generated with two fingers - strange)

    Anyway I know when QPinchGesture ends


    So I could post mouseReleaseEvent to my item (it should be then forwarded to QGraphicsScene) after pinch gesture is finished, but no matter how I try It fails.
    I read that event propagation is from QGraphicsScene to the items, however in my log I can see that first items receives mouseReleaseEvent and then QGraphicsScene.
    Anyway I have tried sending to QGraphicsScene and QGraphicsItem - QApplication::sendEvent returns false If I post to QGraphicsView - result is true - but neither QGraphicsScene nor my item receives this event, generally:

    QMouseEvent event(QEvent::MouseButtonRelease,QPoint(floor->mainviewItem->boundingRect().width()/2,floor->mainviewItem->boundingRect().height()/2),Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
        bool ret=QApplication::sendEvent(floor->mainviewItem, &event);

    I cant send QGraphicsSceneMouseEvent but I read that if I post QMouseEvent to QGraphicsView it will be transformed to QGraphicsSceneMouseEvent and delivered to the scene, so

    QMouseEvent event(QEvent::MouseButtonRelease,QPoint(100,100),Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
        bool ret=QApplication::sendEvent(graphicsView, &event);

    sendEvent returns true, but I can't see the event being delivered to the scene or item.

    How to solve this issue? I would like to deliver mouseReleaseEvent to the scene after pinch is finished.

    Best Regards

  • I came across the same problem 3 years after this issue was first posted. I can successfully post a mouseReleaseEvent when the pinch gesture is finished:

        if (gesture->state() == Qt::GestureFinished)
            QMouseEvent eve( (QEvent::MouseButtonRelease), QCursor::pos(),

    The problem is that still after that mouse release is delivered, the application doesn't react the next time I touch the screen to try to press a button, or pan the image with one finger. However if I move the mouse just after the pinch is finalised, the next time I touch the screen it DOES react. Any idea of why this happens? And why in the first place the mouse button is not released if the pinch is finalised by "removing the first finger fist"?

Log in to reply