Important: Please read the Qt Code of Conduct -

When is QGraphicsSceneMouseEvent.pos() (item coordinate system) valid ? Who is picking items?

  • I find that it often returns (0,0). It is not clear whether the QGraphicsView is picking graphic items, or sending mouse events to the scene even if no item contains the graphics device pointer (mouse, cursor.)

    I reimplemented the QGraphicsScene.mouseMoveEvent() handler, and I also have reimplemented QGraphicItems.contains() so that for certain graphic items, only the edges of the graphic items contain a pick point (the cursor.) I am guessing that if I had NOT reimplemented, the default handler does picking and fills in the item coordinates so that QGraphicsSceneMouseEvents are never delivered to handlers in graphic items with pos() returning (0,0)?

    It seems to me that the documentation could be clearer on this point.

    (And what use is QGraphicsSceneMouseEvent.screenPos() ? I find the view coordinates more useful, and strange that the screen coordinates are exposed.)

  • Also, I find that QGraphicsItem.mapFromScene() isn't adequate for QGraphicsSceneMouseEvent.scenePos() for items that have the ItemIgnoresTransform flag set. The documentation is clear that it shouldn't be used. Thus to get from a QGraphicsSceneMouseEvent to a local (item) coordinate, it seems you must map from the scene to view:

    @pointViewCS = view.mapFromScene(event.scenePos())@

    and then the item map from view to local:

    transform, isInvertible = self.deviceTransform(view.viewportTransform()).inverted()
    pointLocalCS =

    The context is, I am implementing a custom control in a graphics view without using widgets. I don't want the control to scale with the view so I set ItemIgnores Transformation. But the control needs to receive mouse events and I need to work in local coordinates to implement the control.

Log in to reply