PDA

View Full Version : How to remove animations?



mirelon
3rd February 2010, 21:20
I have a game with many animations. They are QPropertyAnimation applied to graphics items. I made a connect between signal finished() and my custom slot animationFinished(). At some point I want to cancel all animations and clean all graphics. I use this code to clean all:


foreach(QGraphicsItem* git,graphicsView->scene()->items()){
graphicsView->scene()->removeItem(git);
}

The graphics view is clear after executing this code. But after some time (maybe when some animation finishes), the animationFinished() is executed. I assume my code removes the graphics items, but the property animations are still there. How can I remove them?

mrvk
4th February 2010, 09:41
When you start the animation, you can use the pass the argument QAbstractAnimation::DeleteWhenStopped to the start function of the QPropertyAnimation.

removeItem will not delete the graphicsItem. It will just remove it from the scene, hence its child, the QPropertyAnimation will not be deleted.
To delete all the graphical items, use 'clear' slot of the graphicsscene.