Search code examples
qtqgraphicssceneqgraphicsitem

Map mouse coordinates to QGraphicsScene coordinates


I have a QWidget with a QGraphicsScene member. What I to do is for the QWidget to receive a mousePressEvent (by overloading) and then find a graphics item in the scene from the mouse coordinates supplied by the event.

So my question is how do I convert the mouse coordinates to graphics scene coordinates so I can compare to the graphics item?

Thanks


Solution

  • Use QGraphicsView::mapToScene to convert the mouse position to the coordinates system of your scene.