
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQVariantAnimation class provides an abstract base class for animations.More...
| Header: | #include <QVariantAnimation> |
| Since: | Qt 4.6 |
| Inherits: | QAbstractAnimation |
| Inherited By: |
|
|
| QVariantAnimation(QObject * parent = 0) | |
| ~QVariantAnimation() | |
| QVariant | currentValue() const |
| QEasingCurve | easingCurve() const |
| QVariant | endValue() const |
| QVariant | keyValueAt(qreal step) const |
| KeyValues | keyValues() const |
| void | setDuration(int msecs) |
| void | setEasingCurve(const QEasingCurve & easing) |
| void | setEndValue(const QVariant & value) |
| void | setKeyValueAt(qreal step, const QVariant & value) |
| void | setKeyValues(const KeyValues & keyValues) |
| void | setStartValue(const QVariant & value) |
| QVariant | startValue() const |
| virtual int | duration() const |
| void | valueChanged(const QVariant & value) |
| virtual QVariant | interpolated(const QVariant & from, const QVariant & to, qreal progress) const |
| virtual void | updateCurrentValue(const QVariant & value) = 0 |
| virtual bool | event(QEvent * event) |
| virtual void | updateCurrentTime(int) |
| virtual void | updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) |
| void | qRegisterAnimationInterpolator(QVariant(* ) ( const T & from, const T & to, qreal progress ) func) |
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.
This is a typedef forQPair<qreal,QVariant>.
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:
| QVariant | currentValue() const |
Notifier signal:
| void | valueChanged(const QVariant & value) |
See alsostartValue andendValue.
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 int | duration() const |
| void | setDuration(int msecs) |
See alsoQAbstractAnimation::duration().
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:
| QEasingCurve | easingCurve() const |
| void | setEasingCurve(const QEasingCurve & easing) |
This property holds the end value of the animation.
This property describes the end value of the animation.
Access functions:
| QVariant | endValue() const |
| void | setEndValue(const QVariant & value) |
See alsostartValue.
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:
| QVariant | startValue() const |
| void | setStartValue(const QVariant & value) |
See alsoendValue.
Construct aQVariantAnimation object.parent is passed toQAbstractAnimation's constructor.
Destroys the animation.
[virtual protected]bool QVariantAnimation::event(QEvent * event)Reimplemented fromQObject::event().
[virtual protected]QVariant QVariantAnimation::interpolated(constQVariant & from, constQVariant & to,qreal progress) constThis 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.
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().
Returns the key frames of this animation.
See alsokeyValueAt() andsetKeyValues().
Creates a key frame at the givenstep with the givenvalue. The givenstep must be in the range 0 to 1.
See alsosetKeyValues() andkeyValueAt().
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().
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.