QVariantAnimation 类提供动画的基类。 更多...
头: | #include <QVariantAnimation> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QAbstractAnimation |
继承者: |
KeyValue | |
KeyValues |
|
|
QVariantAnimation (QObject * parent = nullptr) | |
virtual | ~QVariantAnimation () |
QBindable<int> | bindableDuration () |
QBindable<QEasingCurve> | bindableEasingCurve () |
QVariant | currentValue () const |
QEasingCurve | easingCurve () const |
QVariant | endValue () const |
QVariant | keyValueAt (qreal step ) const |
QVariantAnimation::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 QVariantAnimation::KeyValues & keyValues ) |
void | setStartValue (const QVariant & value ) |
QVariant | startValue () const |
virtual int | duration () const override |
void | valueChanged (const QVariant & value ) |
virtual QVariant | interpolated (const QVariant & from , const QVariant & to , qreal progress ) const |
virtual void | updateCurrentValue (const QVariant & value ) |
virtual bool | event (QEvent * event ) override |
virtual void | updateCurrentTime (int) override |
virtual void | updateState (QAbstractAnimation::State newState , QAbstractAnimation::State oldState ) override |
void | qRegisterAnimationInterpolator (QVariant (*)(const T &, const T &, qreal) func ) |
此类属于 动画框架 . It serves as a base class for property and item animations, with functions for shared functionality.
The class performs interpolation over QVariant s, but leaves using the interpolated values to its subclasses. Currently, Qt provides QPropertyAnimation , which animates Qt properties 。见 QPropertyAnimation class description if you wish to animate such properties.
You can then set start and end values for the property by calling setStartValue () 和 setEndValue (),最后调用 start () to start the animation. QVariantAnimation will interpolate the property of the target object and emit valueChanged (). To react to a change in the current value you have to reimplement the updateCurrentValue () virtual function or connect to said signal.
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 how QVariantAnimation interpolates the values. You can set an easing curve by calling setEasingCurve (), and configure the duration by calling setDuration (). You can change how the QVariant s are interpolated by creating a subclass of QVariantAnimation, and reimplementing the virtual interpolated () 函数。
Subclassing QVariantAnimation can be an alternative if you have QVariant s that you do not wish to declare as Qt properties. Note, however, that you in most cases will be better off declaring your QVariant as a property.
并非所有 QVariant types are supported. Below is a list of currently supported QVariant 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.
范例:
QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) { ... return QColor(...); } ... qRegisterAnimationInterpolator<QColor>(myColorInterpolator);
Another option is to reimplement interpolated (), which returns interpolation values for the value being interpolated.
另请参阅 QPropertyAnimation , QAbstractAnimation ,和 动画框架 .
[alias]
QVariantAnimation::
KeyValue
This is a typedef for std::pair<qreal, QVariant >.
这是 typedef 对于 QList < KeyValue >
[read-only]
currentValue
: const
QVariant
This property holds the current value of the animation.
This property describes the current value; an interpolated value between the start value 和 end value , using the current time for progress. The value itself is obtained from interpolated (), which is called repeatedly as the animation is running.
QVariantAnimation calls the virtual updateCurrentValue () 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 Qt properties .
访问函数:
QVariant | currentValue () const |
通知程序信号:
void | valueChanged (const QVariant & value ) |
另请参阅 startValue and endValue .
[bindable]
duration
:
int
注意: 此特性支持 QProperty 绑定。
This property holds the duration of the animation
This property describes the duration in milliseconds of the animation. The default duration is 250 milliseconds.
另请参阅 QAbstractAnimation::duration ().
[bindable]
easingCurve
:
QEasingCurve
注意: 此特性支持 QProperty 绑定。
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 is QEasingCurve::InOutElastic , which provides an elastic effect on the values of the interpolated variant.
QVariantAnimation will use the QEasingCurve::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 when interpolated () is called. Also, the steps in the keyValues are referring to this effective progress.
The easing curve is used with the interpolator, the interpolated () virtual function, and the animation's duration to control how the current value changes as the animation progresses.
This property holds the end value of the animation
This property describes the end value of the animation.
访问函数:
QVariant | endValue () const |
void | setEndValue (const QVariant & value ) |
另请参阅 startValue .
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 null QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.
访问函数:
QVariant | startValue () const |
void | setStartValue (const QVariant & value ) |
另请参阅 endValue .
Construct a QVariantAnimation object. parent 会被传递给 QAbstractAnimation 的构造函数。
[virtual noexcept]
QVariantAnimation::
~QVariantAnimation
()
Destroys the animation.
[override virtual protected]
bool
QVariantAnimation::
event
(
QEvent
*
event
)
重实现: QAbstractAnimation::event (QEvent *event).
[virtual protected]
QVariant
QVariantAnimation::
interpolated
(const
QVariant
&
from
, const
QVariant
&
to
,
qreal
progress
) const
This virtual function returns the linear interpolation between variants from and to , at progress , usually a value between 0 and 1. You can reimplement this function in a subclass of QVariantAnimation to provide your own interpolation algorithm.
Note that in order for the interpolation to work with a QEasingCurve that return a value smaller than 0 or larger than 1 (such as QEasingCurve::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 the QVariantAnimation implementation of this function if you want your class to handle the types already supported by Qt (see class QVariantAnimation description for a list of supported types).
另请参阅 QEasingCurve .
Returns the key frame value for the given step . The given step must be in the range 0 to 1. If there is no KeyValue for step , it returns an invalid QVariant .
另请参阅 keyValues () 和 setKeyValueAt ().
Returns the key frames of this animation.
另请参阅 keyValueAt () 和 setKeyValues ().
Creates a key frame at the given step 采用给定 value . The given step must be in the range 0 to 1.
另请参阅 setKeyValues () 和 keyValueAt ().
Replaces the current set of key frames with the given keyValues . the step of the key frames must be in the range 0 to 1.
另请参阅 keyValues () 和 keyValueAt ().
[override virtual protected]
void
QVariantAnimation::
updateCurrentTime
(
int
)
重实现: QAbstractAnimation::updateCurrentTime (int currentTime).
[virtual protected]
void
QVariantAnimation::
updateCurrentValue
(const
QVariant
&
value
)
This virtual function is called every time the animation's current value changes. The value argument is the new current value.
基类实现什么都不做。
另请参阅 currentValue .
[override virtual protected]
void
QVariantAnimation::
updateState
(
QAbstractAnimation::State
newState
,
QAbstractAnimation::State
oldState
)
重实现: QAbstractAnimation::updateState (QAbstractAnimation::State newState, QAbstractAnimation::State oldState).
[signal]
void
QVariantAnimation::
valueChanged
(const
QVariant
&
value
)
QVariantAnimation emits this signal whenever the current value 改变。
注意: 通知程序信号对于特性 currentValue .
另请参阅 currentValue , startValue ,和 endValue .
Registers a custom interpolator
func
for the template type
T
. The interpolator has to be registered before the animation is constructed. To unregister (and use the default interpolator) set
func
to
nullptr
.
注意: 此函数是 thread-safe .