Hi,

I have a problem with the position of the graphics items in my scene and I don't know how to solve it.

I have one QGraphicsLineItem on my scene and, when I click on it, it creates a new one. It should draw a horizontal line starting in the last point of the previous item and finishing 30px to the right.

All of them are childs of biggers QGraphicsItems, pressing a button I enable the user to move those big parent items (moving the childs as well). Some of those objects have two, three or more of the small QGraphicsLineItem.

So far, I was doing it with:

Qt Code:
  1. //pseudocode
  2. newItem->setParentItem(parentItem);
  3.  
  4. QPointF prevItemEndingPoint = previousItem.line().p2();
  5. QPointF startingPoint = newItem->mapFromItem(previousItem, prevItemEndingPoint );
  6. QPointF endingPoint = startingPoint;
  7. endingPoint.setX(startingPoint.rx() + 30);
  8.  
  9. newItem.setLine(previousItem, endingPoint);
To copy to clipboard, switch view to plain text mode 

It worked fine until now. I've just realized it doesn't work when the I create an item of a different parent and I have moved one the previous parent before, like for instance:





Now I want to create a new GraphicsItem, so I click in A (pink object is desired, but green is created)



how I can map those coords? I think I have tried everything...

thanks!