PDA

View Full Version : Add Offset/Border/Boundary between QGraphicsScene and QGraphicsItem



pratham_shah
20th September 2012, 14:08
Hi,
I have a QGraphicsScene containing many custom QGraphicsItem.
All the QGraphicsItems are movable. When I move the QGraphicsItem towards any edge of the QGraphicsScene the scene automatically expands.

My problem is that I want to have some offset ( a kind of border ) between the scene and the graphics item, so that when I move the item to the edge of the scene the scene should expand with the offset in place.

I tried using QGraphicsScene::setSceneRect(), but using this method freezes the size of the scene, so the scene doesnt expand automatically on graphics item move.

Any pointers would be helpful.

d_stranz
20th September 2012, 16:12
Change the custom graphics item so that the boundingRect() method returns the rect + border instead of just the rect of the item.

Or center the custom item as a child inside a QGraphicsRectItem whose size is adjusted to include the border. This might be more flexible, because then you can change the rect item's size and the position of the custom item inside it without affecting the custom item itself.