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:
//pseudocode
newItem->setParentItem(parentItem);
QPointF prevItemEndingPoint
= previousItem.
line().
p2();
QPointF startingPoint
= newItem
->mapFromItem
(previousItem, prevItemEndingPoint
);
QPointF endingPoint
= startingPoint;
endingPoint.setX(startingPoint.rx() + 30);
newItem.setLine(previousItem, endingPoint);
//pseudocode
QGraphicsLineItem* newItem = new QGraphicsLineItem();
newItem->setParentItem(parentItem);
QPointF prevItemEndingPoint = previousItem.line().p2();
QPointF startingPoint = newItem->mapFromItem(previousItem, prevItemEndingPoint );
QPointF endingPoint = startingPoint;
endingPoint.setX(startingPoint.rx() + 30);
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!
Bookmarks