En esta página

QPropertyAnimation Class

La clase QPropertyAnimation anima las propiedades Qt. Más...

Cabecera: #include <QPropertyAnimation>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Hereda: QVariantAnimation

Propiedades

Funciones públicas

QPropertyAnimation(QObject *parent = nullptr)
QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = nullptr)
virtual ~QPropertyAnimation()
QBindable<QByteArray> bindablePropertyName()
QBindable<QObject *> bindableTargetObject()
QByteArray propertyName() const
void setPropertyName(const QByteArray &propertyName)
void setTargetObject(QObject *target)
QObject *targetObject() const

Funciones protegidas reimplementadas

virtual bool event(QEvent *event) override
virtual void updateCurrentValue(const QVariant &value) override
virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) override

Descripción Detallada

QPropertyAnimation interpola sobre las propiedades Qt. Como los valores de las propiedades se almacenan en QVariants, la clase hereda QVariantAnimation, y soporta animación del mismo meta types que su superclase.

Una clase que declare propiedades debe ser una QObject. Para que sea posible animar una propiedad, debe proporcionar un setter (para que QPropertyAnimation pueda establecer el valor de la propiedad). Observa que esto hace posible animar muchos de los widgets de Qt. Veamos un ejemplo:

#include <QApplication>
#include <QPushButton>
#include <QPropertyAnimation>

class MyButtonWidget : public QWidget
{
public:
    MyButtonWidget(QWidget *parent = nullptr);
};

MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
{
    QPushButton *button = new QPushButton(tr("Animated Button"), this);
    QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
    anim->setDuration(10000);
    anim->setStartValue(QPoint(0, 0));
    anim->setEndValue(QPoint(100, 250));
    anim->start();
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MyButtonWidget buttonAnimWidget;
    buttonAnimWidget.resize(QSize(800, 600));
    buttonAnimWidget.show();
    return a.exec();
}

Nota: También puedes controlar la duración de una animación eligiendo delete policy al iniciar la animación.

El nombre de la propiedad y la instancia QObject de la propiedad que debe ser animada se pasan al constructor. A continuación, puede especificar el valor inicial y final de la propiedad. El procedimiento es igual para las propiedades de las clases que has implementado tú mismo-sólo tienes que comprobar con QVariantAnimation que tu tipo QVariant está soportado.

La descripción de la clase QVariantAnimation explica cómo configurar la animación en detalle. Ten en cuenta, sin embargo, que si no se establece un valor de inicio, la propiedad comenzará en el valor que tenía cuando se creó la instancia de QPropertyAnimation.

QPropertyAnimation funciona a las mil maravillas. Para animaciones complejas que, por ejemplo, contienen varios objetos, se proporciona QAnimationGroup. Un grupo de animación es una animación que puede contener otras animaciones, y que puede gestionar cuando se reproducen sus animaciones. Mira QParallelAnimationGroup para ver un ejemplo.

Véase también QVariantAnimation, QAnimationGroup, y El marco de animación.

Documentación de propiedades

[bindable] propertyName : QByteArray

Nota: Esta propiedad soporta enlaces QProperty.

Esta propiedad define el nombre de la propiedad objetivo para esta animación

Esta propiedad define el nombre de la propiedad objetivo para esta animación. El nombre de la propiedad es necesario para que la animación funcione.

Funciones de acceso:

QByteArray propertyName() const
void setPropertyName(const QByteArray &propertyName)

[bindable] targetObject : QObject*

Nota: Esta propiedad soporta enlaces QProperty.

Esta propiedad define el objetivo QObject para esta animación.

Esta propiedad define el QObject objetivo para esta animación.

Funciones de acceso:

QObject *targetObject() const
void setTargetObject(QObject *target)

Documentación de Funciones Miembro

QPropertyAnimation::QPropertyAnimation(QObject *parent = nullptr)

Construye un objeto QPropertyAnimation. parent se pasa al constructor de QObject.

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

Construye un objeto QPropertyAnimation. parent se pasa al constructor de QObject. La animación cambia la propiedad propertyName en target. La duración por defecto es de 250ms.

Ver también targetObject y propertyName.

[virtual noexcept] QPropertyAnimation::~QPropertyAnimation()

Destruye la instancia QPropertyAnimation.

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

Reimplementa: QVariantAnimation::event(QEvent *event).

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

Reimplementa: QVariantAnimation::updateCurrentValue(const QVariant &value).

Esta función virtual es llamada por QVariantAnimation cada vez que cambia el valor actual. value es el nuevo valor actualizado. Actualiza el valor actual de la propiedad en el objeto destino, a menos que se detenga la animación.

Ver también currentValue y currentTime.

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

Reimplementa: QVariantAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState).

Si el startValue no está definido cuando el estado de la animación cambia de Detenido a En ejecución, el valor actual de la propiedad se utiliza como valor inicial de la animación.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.