- class QPropertyAnimation#
The
QPropertyAnimation
class animates Qt properties. More…New in version 4.6.
Synopsis#
Properties#
propertyNameᅟ
- The target property name for this animationtargetObjectᅟ
- The target QObject for this animation
Methods#
def
__init__()
def
propertyName()
def
targetObject()
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 inQVariant
s, the class inheritsQVariantAnimation
, and supports animation of the samemeta 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 thatQPropertyAnimation
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 withQVariantAnimation
that yourQVariant
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 theQPropertyAnimation
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 atQParallelAnimationGroup
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:
This property holds the target
QObject
for this animation..This property defines the target
QObject
for this animation.- Access functions:
Construct a
QPropertyAnimation
object.parent
is passed toQObject
‘s constructor.- __init__(target, propertyName[, parent=None])
- Parameters:
target –
QObject
propertyName –
QByteArray
parent –
QObject
Construct a
QPropertyAnimation
object.parent
is passed toQObject
‘s constructor. The animation changes the propertypropertyName
ontarget
. The default duration is 250ms.See also
- propertyName()#
- Return type:
See also
Getter of property
propertyNameᅟ
.- setPropertyName(propertyName)#
- Parameters:
propertyName –
QByteArray
See also
Setter of property
propertyNameᅟ
.Setter of property
targetObjectᅟ
.- targetObject()#
- Return type:
See also
Getter of property
targetObjectᅟ
.