How to move all QGraphicsObject in QGraphicsScene to center?
-
I have a collection of QGraphicsObject in a QGraphicsScene. At the moment of creating the QGraphicsScene, I would like to position the center of all QGraphicsObjects together as a group (i.e, keeping the relative positions of the individual QGraphicsObechts) to the center of the QGraphicsScene. Any idea how I can do this easily?
-
Hi,
Do you mean put all your graphic objects on top of each other on the centre of the scene ? Or put them all together in one big rectangle and have that thing centred in your scene ?
-
Ok
Can you show how you are doing it currently ?
-
@ModelTech said in How to move all QGraphicsObject in QGraphicsScene to center?:
I thought I had it figured out with (QGraphicsScene::itemsBoundingRect()).moveCenter(QPointF(0, 0)) but this does not seem to do anything.
It does something, just not what you want to ;)
itemsBoundingRect()
returns a rectangle.moveCenter()
moves that rectangle. It has nothing to do with moving any objects ;)What you need to do is get the
itemsBoundingRect()
, then take its center() and then for each item in the scene moveBy() a negative value of the center you got earlier.