Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QVariantAnimation Class

TheQVariantAnimation class provides an abstract base class for animations.More...

Header:#include <QVariantAnimation>
Since: Qt 4.6
Inherits:QAbstractAnimation
Inherited By:

QPropertyAnimation

Public Types

typedefKeyValue
typedefKeyValues

Properties

Public Functions

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

Reimplemented Public Functions

virtual intduration() const

Signals

voidvalueChanged(const QVariant & value)

Protected Functions

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

Reimplemented Protected Functions

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

Related Non-Members

voidqRegisterAnimationInterpolator(QVariant(* ) ( const T & from, const T & to, qreal progress ) func)

Additional Inherited Members

Detailed Description

TheQVariantAnimation class provides an abstract base class for animations.

This class is part ofThe Animation Framework. It serves as a base class for property and item animations, with functions for shared functionality.

QVariantAnimation cannot be used directly as it is an abstract class; it has a pure virtual method calledupdateCurrentValue(). The class performs interpolation overQVariants, but leaves using the interpolated values to its subclasses. Currently, Qt providesQPropertyAnimation, which animates Qtproperties. See theQPropertyAnimation class description if you wish to animate such properties.

You can then set start and end values for the property by callingsetStartValue() andsetEndValue(), and finally callstart() to start the animation.QVariantAnimation will interpolate the property of the target object and emitvalueChanged(). To react to a change in the current value you have to reimplement theupdateCurrentValue() virtual function.

It is also possible to set values at specified steps situated between the start and end value. The interpolation will then touch these points at the specified steps. Note that the start and end values are defined as the key values at 0.0 and 1.0.

There are two ways to affect howQVariantAnimation interpolates the values. You can set an easing curve by callingsetEasingCurve(), and configure the duration by callingsetDuration(). You can change how theQVariants are interpolated by creating a subclass ofQVariantAnimation, and reimplementing the virtualinterpolated() function.

SubclassingQVariantAnimation can be an alternative if you haveQVariants that you do not wish to declare as Qt properties. Note, however, that you in most cases will be better off declaring yourQVariant as a property.

Not allQVariant types are supported. Below is a list of currently supportedQVariant types:

If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself. To do this, you can register an interpolator function for a given type. This function takes 3 parameters: the start value, the end value and the current progress.

Example:

QVariant myColorInterpolator(constQColor&start,constQColor&end,qreal progress){...returnQColor(...);}...qRegisterAnimationInterpolator<QColor>(myColorInterpolator);

Another option is to reimplementinterpolated(), which returns interpolation values for the value being interpolated.

See alsoQPropertyAnimation,QAbstractAnimation, andThe Animation Framework.

Member Type Documentation

typedef QVariantAnimation::KeyValue

This is a typedef forQPair<qreal,QVariant>.

typedef QVariantAnimation::KeyValues

This is a typedef forQVector<KeyValue>

Property Documentation

currentValue : constQVariant

This property holds the current value of the animation.

This property describes the current value; an interpolated value between thestart value and theend value, using the current time for progress. The value itself is obtained frominterpolated(), which is called repeatedly as the animation is running.

QVariantAnimation calls the virtualupdateCurrentValue() function when the current value changes. This is particularly useful for subclasses that need to track updates. For example,QPropertyAnimation uses this function to animate Qtproperties.

Access functions:

QVariantcurrentValue() const

Notifier signal:

voidvalueChanged(const QVariant & value)

See alsostartValue andendValue.

duration :int

This property holds the duration of the animation.

This property describes the duration in milliseconds of the animation. The default duration is 250 milliseconds.

Access functions:

virtual intduration() const
voidsetDuration(int msecs)

See alsoQAbstractAnimation::duration().

easingCurve :QEasingCurve

This property holds the easing curve of the animation.

This property defines the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation. Other curves are provided, for instance,QEasingCurve::InCirc, which provides a circular entry curve. Another example isQEasingCurve::InOutElastic, which provides an elastic effect on the values of the interpolated variant.

QVariantAnimation will use theQEasingCurve::valueForProgress() to transform the "normalized progress" (currentTime /totalDuration) of the animation into the effective progress actually used by the animation. It is this effective progress that will be the progress wheninterpolated() is called. Also, the steps in thekeyValues are referring to this effective progress.

The easing curve is used with the interpolator, theinterpolated() virtual function, the animation's duration, and iterationCount, to control how the current value changes as the animation progresses.

Access functions:

QEasingCurveeasingCurve() const
voidsetEasingCurve(const QEasingCurve & easing)

endValue :QVariant

This property holds the end value of the animation.

This property describes the end value of the animation.

Access functions:

QVariantendValue() const
voidsetEndValue(const QVariant & value)

See alsostartValue.

startValue :QVariant

This property holds the optional start value of the animation.

This property describes the optional start value of the animation. If omitted, or if a nullQVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.

Access functions:

QVariantstartValue() const
voidsetStartValue(const QVariant & value)

See alsoendValue.

Member Function Documentation

QVariantAnimation::QVariantAnimation(QObject * parent = 0)

Construct aQVariantAnimation object.parent is passed toQAbstractAnimation's constructor.

QVariantAnimation::~QVariantAnimation()

Destroys the animation.

[virtual protected]bool QVariantAnimation::event(QEvent * event)

Reimplemented fromQObject::event().

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

This virtual function returns the linear interpolation between variantsfrom andto, atprogress, usually a value between 0 and 1. You can reimplement this function in a subclass ofQVariantAnimation to provide your own interpolation algorithm.

Note that in order for the interpolation to work with aQEasingCurve that return a value smaller than 0 or larger than 1 (such asQEasingCurve::InBack) you should make sure that it can extrapolate. If the semantic of the datatype does not allow extrapolation this function should handle that gracefully.

You should call theQVariantAnimation implementation of this function if you want your class to handle the types already supported by Qt (see classQVariantAnimation description for a list of supported types).

See alsoQEasingCurve.

QVariant QVariantAnimation::keyValueAt(qreal step) const

Returns the key frame value for the givenstep. The givenstep must be in the range 0 to 1. If there is noKeyValue forstep, it returns an invalidQVariant.

See alsokeyValues() andsetKeyValueAt().

KeyValues QVariantAnimation::keyValues() const

Returns the key frames of this animation.

See alsokeyValueAt() andsetKeyValues().

void QVariantAnimation::setKeyValueAt(qreal step, constQVariant & value)

Creates a key frame at the givenstep with the givenvalue. The givenstep must be in the range 0 to 1.

See alsosetKeyValues() andkeyValueAt().

void QVariantAnimation::setKeyValues(constKeyValues & keyValues)

Replaces the current set of key frames with the givenkeyValues. the step of the key frames must be in the range 0 to 1.

See alsokeyValues() andkeyValueAt().

[virtual protected]void QVariantAnimation::updateCurrentTime(int)

Reimplemented fromQAbstractAnimation::updateCurrentTime().

[pure virtual protected]void QVariantAnimation::updateCurrentValue(constQVariant & value)

This pure virtual function is called every time the animation's current value changes. Thevalue argument is the new current value.

See alsocurrentValue.

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

Reimplemented fromQAbstractAnimation::updateState().

Related Non-Members

voidqRegisterAnimationInterpolator(QVariant(* ) ( constT &from, constT &to,qrealprogress ) func)

Registers a custom interpolatorfunc for the template typeT. The interpolator has to be registered before the animation is constructed. To unregister (and use the default interpolator) setfunc to 0.

Note: This function isthread-safe.

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp