6.0.0-rc4Source

QPropertyAnimation Class

The QPropertyAnimation class animates Qt properties. More…

Header#include <QPropertyAnimation>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since4.6
InheritsQVariantAnimation

List of all members, including inherited members

Public Functions

QPropertyAnimation(QObject *parent = nullptr)
QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
~QPropertyAnimation()
QObject *targetObject() const
voidsetTargetObject(QObject *target)
QByteArraypropertyName() const
voidsetPropertyName(const QByteArray &propertyName)

Reimplemented Protected Functions

Detailed Description

A QPropertyAnimation changes a property of an object over time: at each moment it sets the property to the value that QVariantAnimation works out between the start and the end value.

auto *animation = new QPropertyAnimation(button, "geometry");
animation->setDuration(400);
animation->setEndValue(QRect(200, 50, 120, 30));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start(QAbstractAnimation::DeleteWhenStopped);

Without a start value the animation starts from the value that the property has when the animation starts. The property must have a setter, declared with Q_PROPERTY; dynamic properties work as well.

Only one animation changes a property of an object at a time: starting a second one stops the first.

See also QVariantAnimation and QAnimationGroup.

Differences from Qt

The properties are not bindable.

Member Function Documentation

[explicit] QPropertyAnimation::QPropertyAnimation(QObject *parent = nullptr)

Constructs a property animation with the given parent and no target.

See also setTargetObject() and setPropertyName().

QPropertyAnimation::QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)

Constructs a property animation with the given parent that changes the property propertyName of target.

[override] QPropertyAnimation::~QPropertyAnimation()

Destroys the animation, after stopping it.

[override, protected] bool QPropertyAnimation::event(QEvent *event)

Reimplements QVariantAnimation::event().

QByteArray QPropertyAnimation::propertyName() const

Returns the name of the property that the animation changes.

See also setPropertyName().

void QPropertyAnimation::setPropertyName(const QByteArray &propertyName)

Sets the name of the property that the animation changes to propertyName. The property of an animation that runs cannot be changed.

See also propertyName().

void QPropertyAnimation::setTargetObject(QObject *target)

Sets the object whose property the animation changes to target. The target of an animation that runs cannot be changed.

See also targetObject().

QObject * QPropertyAnimation::targetObject() const

Returns the object whose property the animation changes, or nullptr if there is none or it has been deleted.

See also setTargetObject().

[override, protected] void QPropertyAnimation::updateCurrentValue(const QVariant &value)

Reimplements QVariantAnimation::updateCurrentValue().

Sets the property of the target to value. A stopped animation changes nothing, and an animation whose target has been deleted stops.

[override, protected] void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)

Reimplements QVariantAnimation::updateState().

When the animation starts, takes the current value of the property as the start value if none was set, and stops another animation of the same property.