Namespaces

Variants
Actions

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
Compatibility
Platform(s): Any
Symbian
Article
Keywords: Animation framework, QPropertyAnimation, QVariantAnimation
Created: gnuton (22 Dec 2010)
Last edited: hamishwillee (30 Apr 2013)

Overview

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.

Code

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

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

The previous class can be used as follows:

animator.setStartValue(0);
animator.setEndValue(90);
animator.setDuration(500);
animator.setEasingCurve(QEasingCurve::OutQuart);
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.
64 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.

×