内容表

上一话题

QUuid

下一话题

QVersionNumber

QVariantAnimation

QVariantAnimation class provides a base class for animations. 更多

Inheritance diagram of PySide2.QtCore.QVariantAnimation

继承者: QPropertyAnimation

4.6 版新增。

概要

函数

虚函数

信号

详细描述

此类属于 动画框架 . 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() and setEndValue() , and finally call 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() 函数。

子类化 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:

  • Int

  • UInt

  • Double

  • Float

  • QLine

  • QLineF

  • QPoint

  • QPointF

  • QSize

  • QSizeF

  • QRect

  • QRectF

  • QColor

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.

class QVariantAnimation ( [ parent=None ] )
param parent

QObject

构造 QVariantAnimation 对象。 parent 会被传递给 QAbstractAnimation ‘s constructor.

PySide2.QtCore.QVariantAnimation. currentValue ( )
返回类型

object

PySide2.QtCore.QVariantAnimation. easingCurve ( )
返回类型

QEasingCurve

另请参阅

setEasingCurve()

PySide2.QtCore.QVariantAnimation. endValue ( )
返回类型

object

另请参阅

setEndValue()

PySide2.QtCore.QVariantAnimation. interpolated ( from , to , progress )
参数
  • from – object

  • to – object

  • progress qreal

返回类型

object

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 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

PySide2.QtCore.QVariantAnimation. keyValueAt ( step )
参数

step qreal

返回类型

object

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 .

PySide2.QtCore.QVariantAnimation. keyValues ( )
返回类型

Returns the key frames of this animation.

PySide2.QtCore.QVariantAnimation. setDuration ( msecs )
参数

msecs int

另请参阅

duration()

PySide2.QtCore.QVariantAnimation. setEasingCurve ( easing )
参数

easing QEasingCurve

另请参阅

easingCurve()

PySide2.QtCore.QVariantAnimation. setEndValue ( value )
参数

value – object

另请参阅

endValue()

PySide2.QtCore.QVariantAnimation. setKeyValueAt ( step , value )
参数
  • step qreal

  • value – object

Creates a key frame at the given step 采用给定 value . The given step must be in the range 0 to 1.

PySide2.QtCore.QVariantAnimation. setKeyValues ( values )
参数

values

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.

PySide2.QtCore.QVariantAnimation. setStartValue ( value )
参数

value – object

另请参阅

startValue()

PySide2.QtCore.QVariantAnimation. startValue ( )
返回类型

object

另请参阅

setStartValue()

PySide2.QtCore.QVariantAnimation. updateCurrentValue ( value )
参数

value – object

This virtual function is called every time the animation’s current value changes. The value argument is the new current value.

基类实现什么都不做。

另请参阅

currentValue

PySide2.QtCore.QVariantAnimation. valueChanged ( value )
参数

value – object