jano_alex_es
8th September 2009, 10:48
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
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);
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:
http://img171.imageshack.us/img171/7564/13262898.jpg
http://img35.imageshack.us/img35/6559/27455726.jpg
Now I want to create a new GraphicsItem, so I click in A (pink object is desired, but green is created)
http://img36.imageshack.us/img36/2682/31002329.jpg
how I can map those coords? I think I have tried everything...
thanks!
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
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);
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:
http://img171.imageshack.us/img171/7564/13262898.jpg
http://img35.imageshack.us/img35/6559/27455726.jpg
Now I want to create a new GraphicsItem, so I click in A (pink object is desired, but green is created)
http://img36.imageshack.us/img36/2682/31002329.jpg
how I can map those coords? I think I have tried everything...
thanks!