Reputation: 4660
I have a QGraphicsScene where the order of the items is very important. I'd like to add items at a certain index in the items list (i.e. the list that's returned when items()
is called).
I know QList has the removeAt()
and insert()
functions but does QGraphicsScene have something similar, like addItemAt()
or something all these lines? If not, does anyone know of a good way to go about this?
Upvotes: 2
Views: 155
Reputation: 22292
There is no option to specify an order at insertion time. By default, the most recent item added will appear at the top.
You have two options to determine the stacking order of sibling items (items with the same parent) after they have been added to the scene.
Specify a Z value.
Change the insertion order (which applies for items with the same Z value).
If you wish to arrange by Z value, you will need to assign specific Z values to your items and reassign them as needed when adding new items using QGraphicsItem::setZValue().
Or, you can change the insertion order of an item by calling QGraphicsItem::stackBefore().
Upvotes: 1