Getting coordinate relative to QGraphicsItem on mouse click in QGraphicsView
Solved
General and Desktop
-
I have a rectangle QGraphicsView and a QGraphicsItem inside, I want to retrieve the x-position relative to the item when I click in the view.
For example, I have a graphicsview of 1000 px wide and a graphicsItem of 100 px wide, the item is placed at the 500 px point in the view. When I clicked on 502 px in the view, I want it to return something like a QPoint with x=2.
-
I'm not familiar with the graphics view framework, but from the information of doc, I think you can:
step1. map from view to scene byQGraphicsView::mapToScene
.
step2. map from scene to item byQGraphicsItem::mapFromScene
.
I haven't found a direct mapping method from QGraphicsView to QGraphicsItem.