QPropertyAnimation Class
The QPropertyAnimation class animates Qt properties 更多...
头文件: | #include <QPropertyAnimation> |
qmake: | QT += core |
开始支持版本: | Qt 4.6 |
基类: | QVariantAnimation |
属性
- propertyName : QByteArray
- targetObject : QObject *
- 5 个属性继承自 QVariantAnimation
- 6 个属性继承自 QAbstractAnimation
- 1 个属性继承自 QObject
公有函数
QPropertyAnimation(QObject *parent = Q_NULLPTR) | |
QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = Q_NULLPTR) | |
~QPropertyAnimation() | |
QByteArray | propertyName() const |
void | setPropertyName(const QByteArray &propertyName) |
void | setTargetObject(QObject *target) |
QObject * | targetObject() const |
- 13 个公有函数继承自 QVariantAnimation
- 11 个公有函数继承自 QAbstractAnimation
- 32 个公有函数继承自 QObject
重新实现的受保护函数
virtual bool | event(QEvent *event) |
virtual void | updateCurrentValue(const QVariant &value) |
virtual void | updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) |
- 5 个受保护的函数继承自 QVariantAnimation
- 4 个受保护的函数继承自 QAbstractAnimation
- 9 个受保护的函数继承自 QObject
其他继承的成员
- 6 个公有槽函数继承自 QAbstractAnimation
- 1 个公有槽函数继承自 QObject
- 1 个信号继承自 QVariantAnimation
- 4 个信号继承自 QAbstractAnimation
- 2 个信号继承自 QObject
- 11 个静态公有成员继承自 QObject
- 5 个受保护的函数继承自 QVariantAnimation
- 4 个受保护的函数继承自 QAbstractAnimation
- 9 个受保护的函数继承自 QObject
详细描述
The QPropertyAnimation class animates Qt properties
QPropertyAnimation interpolates over Qt properties. As property values are stored in QVariants, 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:
QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry"); animation->setDuration(10000); animation->setStartValue(QRect(0, 0, 100, 30)); animation->setEndValue(QRect(250, 250, 100, 30)); animation->start();
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.
参见 QVariantAnimation, QAnimationGroup, and The Animation Framework.
属性
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.
访问函数:
QByteArray | propertyName() const |
void | setPropertyName(const QByteArray &propertyName) |
targetObject : QObject *
This property holds the target QObject for this animation.
This property defines the target QObject for this animation.
访问函数:
QObject * | targetObject() const |
void | setTargetObject(QObject *target) |
成员函数
QPropertyAnimation::QPropertyAnimation(QObject *parent = Q_NULLPTR)
Construct a QPropertyAnimation object. parent is passed to QObject's constructor.
QPropertyAnimation::QPropertyAnimation(QObject *target, const QByteArray &propertyName, QObject *parent = Q_NULLPTR)
Construct a QPropertyAnimation object. parent is passed to QObject's constructor. The animation changes the property propertyName on target. The default duration is 250ms.
参见 targetObject and propertyName.
QPropertyAnimation::~QPropertyAnimation()
Destroys the QPropertyAnimation instance.
[virtual protected]
bool QPropertyAnimation::event(QEvent *event)
Reimplemented from QObject::event().
[virtual protected]
void QPropertyAnimation::updateCurrentValue(const QVariant &value)
Reimplemented from QVariantAnimation::updateCurrentValue().
This virtual function is called by QVariantAnimation whenever the current value changes. value is the new, updated value. It updates the current value of the property on the target object.
参见 currentValue and currentTime.
[virtual protected]
void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
Reimplemented from QAbstractAnimation::updateState().
If the startValue is not defined when the state of the animation changes from Stopped to Running, the current property value is used as the initial value for the animation.