QVariantAnimation

Inherited by: QPropertyAnimation

Note

This class was introduced in Qt 4.6

Synopsis

Functions

Virtual functions

Signals

Detailed Description

The PySide.QtCore.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.

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

You can then set start and end values for the property by calling PySide.QtCore.QVariantAnimation.setStartValue() and PySide.QtCore.QVariantAnimation.setEndValue() , and finally call PySide.QtCore.QAbstractAnimation.start() to start the animation. PySide.QtCore.QVariantAnimation will interpolate the property of the target object and emit PySide.QtCore.QVariantAnimation.valueChanged() . To react to a change in the current value you have to reimplement the PySide.QtCore.QVariantAnimation.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 PySide.QtCore.QVariantAnimation interpolates the values. You can set an easing curve by calling PySide.QtCore.QVariantAnimation.setEasingCurve() , and configure the duration by calling PySide.QtCore.QVariantAnimation.setDuration() . You can change how the QVariants are interpolated by creating a subclass of PySide.QtCore.QVariantAnimation , and reimplementing the virtual PySide.QtCore.QVariantAnimation.interpolated() function.

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

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

  • Int
  • Double
  • Float
  • QLine
  • QLineF
  • QPoint
  • QPointF
  • QSize
  • QSizeF
  • QRect
  • QRectF
  • QColor

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 PySide.QtCore.QVariantAnimation.interpolated() , which returns interpolation values for the value being interpolated.

class PySide.QtCore.QVariantAnimation([parent=None])
Parameters:parentPySide.QtCore.QObject

Construct a PySide.QtCore.QVariantAnimation object. parent is passed to PySide.QtCore.QAbstractAnimation ‘s constructor.

PySide.QtCore.QVariantAnimation.currentValue()
Return type:object

This property holds the current value of the animation..

This property describes the current value; an interpolated value between the start value and the end value , using the current time for progress. The value itself is obtained from PySide.QtCore.QVariantAnimation.interpolated() , which is called repeatedly as the animation is running.

PySide.QtCore.QVariantAnimation calls the virtual PySide.QtCore.QVariantAnimation.updateCurrentValue() function when the current value changes. This is particularly useful for subclasses that need to track updates. For example, PySide.QtCore.QPropertyAnimation uses this function to animate Qt properties .

PySide.QtCore.QVariantAnimation.easingCurve()
Return type:PySide.QtCore.QEasingCurve

This property holds the easing curve of the animation.

This property defines the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation. Other curves are provided, for instance, QEasingCurve.InCirc , which provides a circular entry curve. Another example is QEasingCurve.InOutElastic , which provides an elastic effect on the values of the interpolated variant.

PySide.QtCore.QVariantAnimation will use the QEasingCurve.valueForProgress() to transform the “normalized progress” ( PySide.QtCore.QAbstractAnimation.currentTime() / totalDuration) of the animation into the effective progress actually used by the animation. It is this effective progress that will be the progress when PySide.QtCore.QVariantAnimation.interpolated() is called. Also, the steps in the keyValues are referring to this effective progress.

The easing curve is used with the interpolator, the PySide.QtCore.QVariantAnimation.interpolated() virtual function, the animation’s duration, and iterationCount, to control how the current value changes as the animation progresses.

PySide.QtCore.QVariantAnimation.endValue()
Return type:object

This property holds the end value of the animation.

This property describes the end value of the animation.

PySide.QtCore.QVariantAnimation.interpolated(from, to, progress)
Parameters:
  • from – object
  • to – object
  • progressPySide.QtCore.qreal
Return type:

object

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 PySide.QtCore.QVariantAnimation to provide your own interpolation algorithm.

Note that in order for the interpolation to work with a PySide.QtCore.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 PySide.QtCore.QVariantAnimation implementation of this function if you want your class to handle the types already supported by Qt (see class PySide.QtCore.QVariantAnimation description for a list of supported types).

PySide.QtCore.QVariantAnimation.keyValueAt(step)
Parameters:stepPySide.QtCore.qreal
Return type:object

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 PySide.QtCore.QVariant .

PySide.QtCore.QVariantAnimation.keyValues()
Return type:

Returns the key frames of this animation.

PySide.QtCore.QVariantAnimation.setDuration(msecs)
Parameters:msecsPySide.QtCore.int

This property holds the duration of the animation.

This property describes the duration in milliseconds of the animation. The default duration is 250 milliseconds.

PySide.QtCore.QVariantAnimation.setEasingCurve(easing)
Parameters:easingPySide.QtCore.QEasingCurve

This property holds the easing curve of the animation.

This property defines the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation. Other curves are provided, for instance, QEasingCurve.InCirc , which provides a circular entry curve. Another example is QEasingCurve.InOutElastic , which provides an elastic effect on the values of the interpolated variant.

PySide.QtCore.QVariantAnimation will use the QEasingCurve.valueForProgress() to transform the “normalized progress” ( PySide.QtCore.QAbstractAnimation.currentTime() / totalDuration) of the animation into the effective progress actually used by the animation. It is this effective progress that will be the progress when PySide.QtCore.QVariantAnimation.interpolated() is called. Also, the steps in the keyValues are referring to this effective progress.

The easing curve is used with the interpolator, the PySide.QtCore.QVariantAnimation.interpolated() virtual function, the animation’s duration, and iterationCount, to control how the current value changes as the animation progresses.

PySide.QtCore.QVariantAnimation.setEndValue(value)
Parameters:value – object

This property holds the end value of the animation.

This property describes the end value of the animation.

PySide.QtCore.QVariantAnimation.setKeyValueAt(step, value)
Parameters:
  • stepPySide.QtCore.qreal
  • value – object

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

PySide.QtCore.QVariantAnimation.setKeyValues(values)
Parameters:values
PySide.QtCore.QVariantAnimation.setStartValue(value)
Parameters:value – object

This property holds the optional start value of the animation.

This property describes the optional start value of the animation. If omitted, or if a null PySide.QtCore.QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.

PySide.QtCore.QVariantAnimation.startValue()
Return type:object

This property holds the optional start value of the animation.

This property describes the optional start value of the animation. If omitted, or if a null PySide.QtCore.QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.

PySide.QtCore.QVariantAnimation.updateCurrentValue(value)
Parameters:value – object

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

PySide.QtCore.QVariantAnimation.valueChanged(value)
Parameters:value – object