The QPropertyAnimation class animates Qt properties. More

Inheritance diagram of PySide6.QtCore.QPropertyAnimation

New in version 4.6.





This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#


This section contains snippets that were automatically translated from C++ to Python and may contain errors.

QPropertyAnimation interpolates over Qt properties . As property values are stored in QVariant s, the class inherits QVariantAnimation , and supports animation of the same meta types as its super class.

A class declaring properties must be a QObject . To make it possible to animate a property, it must provide a setter (so that QPropertyAnimation can set the property’s value). Note that this makes it possible to animate many of Qt’s widgets. Let’s look at an example:

from PySide6.QtWidgets import QApplication
from PySide6.QtWidgets import QPushButton
from PySide6.QtCore import QPropertyAnimation
class MyButtonWidget(QWidget):

# public
    MyButtonWidget(QWidget parent = None)

def __init__(self, QWidget(parent):

    button = QPushButton(tr("Animated Button"), self)
    anim = QPropertyAnimation(button, "pos", self)
    anim.setStartValue(QPoint(0, 0))
    anim.setEndValue(QPoint(100, 250))

if __name__ == "__main__":

    a = QApplication(argc, argv)
    buttonAnimWidget = MyButtonWidget()
    buttonAnimWidget.resize(QSize(800, 600))
    return a.exec()


You can also control an animation’s lifespan by choosing a delete policy while starting the animation.

The property name and the QObject instance of which property should be animated are passed to the constructor. You can then specify the start and end value of the property. The procedure is equal for properties in classes you have implemented yourself–just check with QVariantAnimation that your QVariant type is supported.

The QVariantAnimation class description explains how to set up the animation in detail. Note, however, that if a start value is not set, the property will start at the value it had when the QPropertyAnimation instance was created.

QPropertyAnimation works like a charm on its own. For complex animations that, for instance, contain several objects, QAnimationGroup is provided. An animation group is an animation that can contain other animations, and that can manage when its animations are played. Look at QParallelAnimationGroup for an example.

class PySide6.QtCore.QPropertyAnimation([parent=None])#

PySide6.QtCore.QPropertyAnimation(target, propertyName[, parent=None])


Construct a QPropertyAnimation object. parent is passed to QObject ‘s constructor.

Construct a QPropertyAnimation object. parent is passed to QObject ‘s constructor. The animation changes the property propertyName on target. The default duration is 250ms.


Properties can be used directly when from __feature__ import true_property is used or via accessor functions otherwise.

property PᅟySide6.QtCore.QPropertyAnimation.propertyName: PySide6.QtCore.QByteArray#

This property holds the target property name for this animation.

This property defines the target property name for this animation. The property name is required for the animation to operate.

Access functions:
property PᅟySide6.QtCore.QPropertyAnimation.targetObject: PySide6.QtCore.QObject#

This property holds the target QObject for this animation..

This property defines the target QObject for this animation.

Access functions:
Return type:


Getter of property propertyName .



See also


Setter of property propertyName .



See also


Setter of property targetObject .

Return type:


Getter of property targetObject .