class QPropertyAnimation

The QPropertyAnimation class animates Qt properties. More

Inheritance diagram of PySide6.QtCore.QPropertyAnimation

Added in version 4.6.

Synopsis

Properties

Methods

Note

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

Warning

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.setDuration(10000)
    anim.setStartValue(QPoint(0, 0))
    anim.setEndValue(QPoint(100, 250))
    anim.start()

if __name__ == "__main__":

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

Note

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.

Note

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

property propertyNameᅟ: 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 targetObjectᅟ: QObject

This property holds the target QObject for this animation..

This property defines the target QObject for this animation.

Access functions:
__init__([parent=None])
Parameters:

parentQObject

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

__init__(target, propertyName[, parent=None])
Parameters:

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

propertyName()
Return type:

QByteArray

Getter of property propertyNameᅟ .

setPropertyName(propertyName)
Parameters:

propertyNameQByteArray

See also

propertyName()

Setter of property propertyNameᅟ .

setTargetObject(target)
Parameters:

targetQObject

See also

targetObject()

Setter of property targetObjectᅟ .

targetObject()
Return type:

QObject

Getter of property targetObjectᅟ .