QVariantAnimation

The QVariantAnimation class provides a base class for animations. More

Inheritance diagram of PySide6.QtCore.QVariantAnimation

Inherited by: QPropertyAnimation

New in version 4.6.

Synopsis

Functions

Virtual functions

Detailed Description

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

The class performs interpolation over QVariant s, 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 or connect to said signal.

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 QVariant s are interpolated by creating a subclass of QVariantAnimation , and reimplementing the virtual interpolated() function.

Subclassing QVariantAnimation can be an alternative if you have 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 QVariant as a property.

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

  • Int

  • UInt

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

class PySide6.QtCore.QVariantAnimation([parent=None])
Parameters

parentPySide6.QtCore.QObject

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

PySide6.QtCore.QVariantAnimation.currentValue()
Return type

object

PySide6.QtCore.QVariantAnimation.easingCurve()
Return type

PySide6.QtCore.QEasingCurve

See also

setEasingCurve()

PySide6.QtCore.QVariantAnimation.endValue()
Return type

object

See also

setEndValue()

PySide6.QtCore.QVariantAnimation.interpolated(from, to, progress)
Parameters
  • from – object

  • to – object

  • progress – float

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 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 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

PySide6.QtCore.QVariantAnimation.keyValueAt(step)
Parameters

step – float

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

See also

keyValues() setKeyValueAt()

PySide6.QtCore.QVariantAnimation.setDuration(msecs)
Parameters

msecs – int

See also

duration()

PySide6.QtCore.QVariantAnimation.setEasingCurve(easing)
Parameters

easingPySide6.QtCore.QEasingCurve

See also

easingCurve()

PySide6.QtCore.QVariantAnimation.setEndValue(value)
Parameters

value – object

See also

endValue()

PySide6.QtCore.QVariantAnimation.setKeyValueAt(step, value)
Parameters
  • step – float

  • 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.

See also

setKeyValues() keyValueAt()

PySide6.QtCore.QVariantAnimation.setStartValue(value)
Parameters

value – object

See also

startValue()

PySide6.QtCore.QVariantAnimation.startValue()
Return type

object

See also

setStartValue()

PySide6.QtCore.QVariantAnimation.updateCurrentValue(value)
Parameters

value – object

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

The base class implementation does nothing.

See also

currentValue

PySide6.QtCore.QVariantAnimation.valueChanged(value)
Parameters

value – object

QVariantAnimation emits this signal whenever the current value changes.