6.0.0-rc4Source

QVariantAnimation Class

The QVariantAnimation class provides a base class for animations. More…

Header#include <QVariantAnimation>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since4.6
InheritsQAbstractAnimation
Inherited byQPropertyAnimation

List of all members, including inherited members

Public Types

typedefKeyValue
typedefKeyValues

Public Functions

QVariantAnimation(QObject *parent = nullptr)
~QVariantAnimation()
QVariantstartValue() const
voidsetStartValue(const QVariant &value)
QVariantendValue() const
voidsetEndValue(const QVariant &value)
QVariantkeyValueAt(qreal step) const
voidsetKeyValueAt(qreal step, const QVariant &value)
KeyValueskeyValues() const
voidsetKeyValues(const KeyValues &values)
QVariantcurrentValue() const
voidsetDuration(int msecs)
QEasingCurveeasingCurve() const
voidsetEasingCurve(const QEasingCurve &easing)

Reimplemented Public Functions

intduration() const

Signals

voidvalueChanged(const QVariant &value)

Protected Functions

virtual voidupdateCurrentValue(const QVariant &value)
virtual QVariantinterpolated(const QVariant &from, const QVariant &to, qreal progress) const

Reimplemented Protected Functions

boolevent(QEvent *event)
voidupdateCurrentTime(int currentTime)
voidupdateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)

Detailed Description

A QVariantAnimation changes a value over its duration: from a start value to an end value, by way of any key values in between. As the current time moves, it works out the current value, emits valueChanged() and calls updateCurrentValue().

QVariantAnimation animation;
animation.setDuration(500);
animation.setStartValue(0);
animation.setKeyValueAt(0.8, 110);
animation.setEndValue(100);
animation.setEasingCurve(QEasingCurve::OutCubic);
QObject::connect(&animation, &QVariantAnimation::valueChanged, [&](const QVariant &value) {
    bar.setValue(value.toInt());
});
animation.start();

The values between two key values are interpolated. That works for int, unsigned int, long long, unsigned long long, double, float, QPoint, QPointF, QSize, QSizeF, QLine, QLineF, QRect and QRectF; register a function for another type with qRegisterAnimationInterpolator(). A value of a type without one changes from the start value to the end value at the end. The easing curve shapes how the progress follows the time.

See also QPropertyAnimation and QEasingCurve.

Differences from Qt

The properties are not bindable. A key value is a std::pair, as Nt has no QPair.

Member Type Documentation

typedef QVariantAnimation::KeyValue

A step, from 0 at the start to 1 at the end, and the value that the animation has there.

typedef QVariantAnimation::KeyValues

A list of key values, ordered by their steps.

Member Function Documentation

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

Constructs an animation with the given parent, a duration of 250 milliseconds and a linear easing curve.

[override] QVariantAnimation::~QVariantAnimation()

Destroys the animation.

QVariant QVariantAnimation::currentValue() const

Returns the value that the animation has at its current time. It is invalid before the animation has a start and an end value and was updated for the first time.

See also valueChanged() and updateCurrentValue().

[override] int QVariantAnimation::duration() const

Reimplements QAbstractAnimation::duration().

Returns the duration of one loop in milliseconds, which is 250 by default.

See also setDuration().

QEasingCurve QVariantAnimation::easingCurve() const

Returns the easing curve of the animation, which is linear by default.

See also setEasingCurve().

QVariant QVariantAnimation::endValue() const

Returns the value that the animation ends with, which is the key value at step 1. It is invalid if none was set.

See also setEndValue() and startValue().

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

Reimplements QAbstractAnimation::event().

[virtual, protected] QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const

Returns the value that lies between from and to at progress, which is 0 at from and 1 at to and outside that range for an easing curve that overshoots. The default implementation uses the function that is registered for the type of the values, and for a type without one returns from until progress reaches 1 and to from then on.

QVariant QVariantAnimation::keyValueAt(qreal step) const

Returns the key value at step, or an invalid variant if there is none at exactly that step.

See also setKeyValueAt() and keyValues().

KeyValues QVariantAnimation::keyValues() const

Returns the key values of the animation, ordered by their steps.

See also setKeyValues() and keyValueAt().

void QVariantAnimation::setDuration(int msecs)

Sets the duration of one loop to msecs milliseconds, which must not be negative.

See also duration().

void QVariantAnimation::setEasingCurve(const QEasingCurve &easing)

Sets the easing curve of the animation to easing. The curve maps the part of the duration that has passed to the progress between the start and the end value: an animation can start slowly, overshoot its end, or bounce.

See also easingCurve().

void QVariantAnimation::setEndValue(const QVariant &value)

Sets the value that the animation ends with to value.

See also endValue() and setStartValue().

void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value)

Makes value the value of the animation at step, which is between 0 for the start and 1 for the end. An invalid value removes the key value at that step.

See also keyValueAt() and setKeyValues().

void QVariantAnimation::setKeyValues(const KeyValues &values)

Replaces the key values of the animation by values, which need not be ordered.

See also keyValues() and setKeyValueAt().

void QVariantAnimation::setStartValue(const QVariant &value)

Sets the value that the animation starts with to value.

See also startValue() and setEndValue().

QVariant QVariantAnimation::startValue() const

Returns the value that the animation starts with, which is the key value at step 0. It is invalid if none was set.

See also setStartValue() and endValue().

[override, protected] void QVariantAnimation::updateCurrentTime(int currentTime)

Reimplements QAbstractAnimation::updateCurrentTime().

[virtual, protected] void QVariantAnimation::updateCurrentValue(const QVariant &value)

Called each time the animation has been updated, with its current value in value, also when the value is the same as before. The default implementation does nothing; connect to valueChanged() to be told of changes only.

See also currentValue().

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

Reimplements QAbstractAnimation::updateState().

[signal] void QVariantAnimation::valueChanged(const QVariant &value)

This signal is emitted when the current value of the animation has changed, with the new value in value.

See also currentValue() and updateCurrentValue().