Home · All Classes · Modules

QVariantAnimation Class Reference
[QtCore module]

The QVariantAnimation class provides an abstract base class for animations. More...

Inherits QAbstractAnimation.

Inherited by QPropertyAnimation.

Methods

Qt Signals


Detailed Description

The QVariantAnimation class provides an abstract base class for animations.

This class is part of The Animation Framework. It serves as a base class for property and item animations, with functions for shared functionality.

QVariantAnimation cannot be used directly as it is an abstract class; it has a pure virtual method called updateCurrentValue(). The class performs interpolation over QVariants, but leaves using the interpolated values to its subclasses. Currently, Qt provides QPropertyAnimation, which animates Qt properties. See the QPropertyAnimation class description if you wish to animate such properties.

You can then set start and end values for the property by calling setStartValue() and setEndValue(), and finally call start() to start the animation. QVariantAnimation will interpolate the property of the target object and emit valueChanged(). To react to a change in the current value you have to reimplement the updateCurrentValue() virtual function.

It is also possible to set values at specified steps situated between the start and end value. The interpolation will then touch these points at the specified steps. Note that the start and end values are defined as the key values at 0.0 and 1.0.

There are two ways to affect how QVariantAnimation interpolates the values. You can set an easing curve by calling setEasingCurve(), and configure the duration by calling setDuration(). You can change how the QVariants are interpolated by creating a subclass of QVariantAnimation, and reimplementing the virtual interpolated() function.

Subclassing QVariantAnimation can be an alternative if you have QVariants that you do not wish to declare as Qt properties. Note, however, that you in most cases will be better off declaring your QVariant as a property.

Not all QVariant types are supported. Below is a list of currently supported QVariant types:

If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself. To do this, you can register an interpolator function for a given type. This function takes 3 parameters: the start value, the end value and the current progress.

Example:

 QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress)
 {
     ...
     return QColor(...);
 }
 ...
 qRegisterAnimationInterpolator<QColor>(myColorInterpolator);

Another option is to reimplement interpolated(), which returns interpolation values for the value being interpolated.


Method Documentation

QVariantAnimation.__init__ (self, QObject parent = None)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Construct a QVariantAnimation object. parent is passed to QAbstractAnimation's constructor.

QVariant QVariantAnimation.currentValue (self)

int QVariantAnimation.duration (self)

QEasingCurve QVariantAnimation.easingCurve (self)

QVariant QVariantAnimation.endValue (self)

bool QVariantAnimation.event (self, QEvent event)

Reimplemented from QObject.event().

QVariant QVariantAnimation.interpolated (self, QVariant from, QVariant to, float progress)

This virtual function returns the linear interpolation between variants from and to, at progress, usually a value between 0 and 1. You can reimplement this function in a subclass of QVariantAnimation to provide your own interpolation algorithm.

Note that in order for the interpolation to work with a QEasingCurve that return a value smaller than 0 or larger than 1 (such as QEasingCurve.InBack) you should make sure that it can extrapolate. If the semantic of the datatype does not allow extrapolation this function should handle that gracefully.

You should call the QVariantAnimation implementation of this function if you want your class to handle the types already supported by Qt (see class QVariantAnimation description for a list of supported types).

See also QEasingCurve.

QVariant QVariantAnimation.keyValueAt (self, float step)

Returns the key frame value for the given step. The given step must be in the range 0 to 1. If there is no KeyValue for step, it returns an invalid QVariant.

See also keyValues() and setKeyValueAt().

unknown-type QVariantAnimation.keyValues (self)

Returns the key frames of this animation.

See also keyValueAt() and setKeyValues().

QVariantAnimation.setDuration (self, int msecs)

QVariantAnimation.setEasingCurve (self, QEasingCurve easing)

QVariantAnimation.setEndValue (self, QVariant value)

QVariantAnimation.setKeyValueAt (self, float step, QVariant value)

Creates a key frame at the given step with the given value. The given step must be in the range 0 to 1.

See also setKeyValues() and keyValueAt().

QVariantAnimation.setKeyValues (self, unknown-type values)

Replaces the current set of key frames with the given keyValues. the step of the key frames must be in the range 0 to 1.

See also keyValues() and keyValueAt().

QVariantAnimation.setStartValue (self, QVariant value)

QVariant QVariantAnimation.startValue (self)

QVariantAnimation.updateCurrentTime (self, int)

Reimplemented from QAbstractAnimation.updateCurrentTime().

QVariantAnimation.updateCurrentValue (self, QVariant value)

This method is abstract and should be reimplemented in any sub-class.

This pure virtual function is called every time the animation's current value changes. The value argument is the new current value.

See also currentValue.

QVariantAnimation.updateState (self, QAbstractAnimation.State newState, QAbstractAnimation.State oldState)

Reimplemented from QAbstractAnimation.updateState().


Qt Signal Documentation

void valueChanged (const QVariant&)

This is the default overload of this signal.

QVariantAnimation emits this signal whenever the current value changes.

See also currentValue, startValue, and endValue.


PyQt 4.12.1 for X11Copyright © Riverbank Computing Ltd and The Qt Company 2015Qt 4.8.7