qtqgraphicsviewqgraphicssceneqgraphicsitemqgraphicsrectitem

Co-ordinates for rectItem wrt to other rectItem in qgraphicsScene


In a qgraphicsScene, we have 2 rectItems added.

enter image description here

Let's say, the red rect is added first and it's topleft coordinates are (x1, y1) wrt to the qgraphicsscene. Now a second blue rect is added in the scene, which overlaps the red rect.

Now how can I get the co-ordinates of red rect wrt to the blue rect's co-ordinate system.

No parenting is done on the rectItems, it's only 2 rectItems added in the scene. tried mapRectFromScene and others also, but didn't get results.


Solution

  • I got it done by,

    x = (red.x - blue.x)

    y = (red.y - blue.y)