Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to use QVariantAnimation

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using Qt C++ for the UI) is deprecated.

This article shows how to use QVariantAnimation.

Article Metadata
Tested with
Devices(s): Any device which supported by Qt
Platform(s): Any
Keywords: Animation framework, QPropertyAnimation, QVariantAnimation
Created: gnuton (22 Dec 2010)
Last edited: hamishwillee (30 Apr 2013)


The Qt Animation framework provides QPropertyAnimation as "default" animator for QObject derived classes. The framework provides also a lower level class: QVariantAnimation. QVariantAnimation cannot be used as it is, since it defines QVariantAnimation::updateCurrentValue as virtual. Since QGraphicsItems are not QObjects, they don't have any qobject property; in this case QVariantAnimation could be used to animate these kind of items directly and avoid subclassing the graphics item itself.


Here is a simple and generic myVariantAnimator class, which emits valueChanged when the value is changed.

#include <QVariantAnimation>
class myVariantAnimator : public QVariantAnimation
virtual ~myVariantAnimator(){};
void updateCurrentValue(const QVariant &value){
emit valueChanged(value);

The previous class can be used as follows:

connect(myVariantAnimator, SIGNAL(valueChanged(const QVariant&)), rcvObj, SLOT(doAnimation()));

In this case, rcvObj::doAnimation will be called as soon as myVariantAnimator::valueChanged is emitted. doAnimation() will be able to animate several items and it's not a problem if it's not a graphics item method.

For more information see: The Animation Framework

This page was last modified on 30 April 2013, at 05:36.
59 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.