Reputation: 13
I created small game when player controls the ellipse and while he moves I draw other Rect items on the screen. While I like that they overlay all other existing items, I dont want new items to cover that ellipse. Is there any way to make that ellipse always on top of anything else?
Upvotes: 0
Views: 126
Reputation: 630
You can use QGraphicsItem::setZValue on your rectangles and ellipse.
For example, upon creating an ellipse item you give it value of 2 and upon creating a rectangle item you give it value of 1. This way ellipse will always overlay any given rectangle.
If you like the way new rectangles overlay existing ones, you can recalculate z values of existing rectangle items upon creating, giving the new one z value of the last created rectangle item incremented by one, while also incrementing z value of ellipse item so it is guaranteed to be more than z value of any given rectangle item.
Upvotes: 2