QVariantAnimation¶
The
QVariantAnimation
class provides a base class for animations. More…
Inherited by: QPropertyAnimation
New in version 4.6.
Synopsis¶
Functions¶
def
currentValue
()def
easingCurve
()def
endValue
()def
keyValueAt
(step)def
keyValues
()def
setDuration
(msecs)def
setEasingCurve
(easing)def
setEndValue
(value)def
setKeyValueAt
(step, value)def
setKeyValues
(values)def
setStartValue
(value)def
startValue
()
Virtual functions¶
def
interpolated
(from, to, progress)def
updateCurrentValue
(value)
Signals¶
def
valueChanged
(value)
Detailed Description¶
This class is part of The Animation Framework . 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 providesQPropertyAnimation
, which animates Qt properties . See theQPropertyAnimation
class description if you wish to animate such properties.You can then set start and end values for the property by calling
setStartValue()
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 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 callingsetEasingCurve()
, and configure the duration by callingsetDuration()
. You can change how theQVariant
s are interpolated by creating a subclass ofQVariantAnimation
, and reimplementing the virtualinterpolated()
function.Subclassing
QVariantAnimation
can be an alternative if you haveQVariant
s 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 all
QVariant
types are supported. Below is a list of currently supportedQVariant
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.
Example:
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 PySide2.QtCore.QVariantAnimation([parent=None])¶
- param parent:
Construct a
QVariantAnimation
object.parent
is passed toQAbstractAnimation
‘s constructor.
- PySide2.QtCore.QVariantAnimation.currentValue()¶
- Return type:
object
This property holds the current value of the animation..
This property describes the current value; an interpolated value between the
start 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 Qt properties .See also
- PySide2.QtCore.QVariantAnimation.easingCurve()¶
- Return type:
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,
InCirc
, which provides a circular entry curve. Another example isInOutElastic
, which provides an elastic effect on the values of the interpolated variant.QVariantAnimation
will use thevalueForProgress()
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, the
interpolated()
virtual function, and the animation’s duration to control how the current value changes as the animation progresses.
- PySide2.QtCore.QVariantAnimation.endValue()¶
- Return type:
object
This property holds the end value of the animation.
This property describes the end value of the animation.
See also
- PySide2.QtCore.QVariantAnimation.interpolated(from, to, progress)¶
- Parameters:
from – object
to – object
progress – float
- Return type:
object
This virtual function returns the linear interpolation between variants
from
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 a
QEasingCurve
that return a value smaller than 0 or larger than 1 (such asInBack
) 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 classQVariantAnimation
description for a list of supported types).See also
- PySide2.QtCore.QVariantAnimation.keyValueAt(step)¶
- Parameters:
step – float
- Return type:
object
Returns the key frame value for the given
step
. The givenstep
must be in the range 0 to 1. If there is noKeyValue
forstep
, it returns an invalidQVariant
.See also
- PySide2.QtCore.QVariantAnimation.keyValues()¶
- Return type:
Returns the key frames of this animation.
See also
- PySide2.QtCore.QVariantAnimation.setDuration(msecs)¶
- Parameters:
msecs – 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.
See also
duration()
- PySide2.QtCore.QVariantAnimation.setEasingCurve(easing)¶
- Parameters:
easing –
PySide2.QtCore.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,
InCirc
, which provides a circular entry curve. Another example isInOutElastic
, which provides an elastic effect on the values of the interpolated variant.QVariantAnimation
will use thevalueForProgress()
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, the
interpolated()
virtual function, and the animation’s duration to control how the current value changes as the animation progresses.
- PySide2.QtCore.QVariantAnimation.setEndValue(value)¶
- Parameters:
value – object
This property holds the end value of the animation.
This property describes the end value of the animation.
See also
- PySide2.QtCore.QVariantAnimation.setKeyValueAt(step, value)¶
- Parameters:
step – float
value – object
Creates a key frame at the given
step
with the givenvalue
. The givenstep
must be in the range 0 to 1.See also
- PySide2.QtCore.QVariantAnimation.setKeyValues(values)¶
- Parameters:
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.See also
- PySide2.QtCore.QVariantAnimation.setStartValue(value)¶
- Parameters:
value – object
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.See also
- PySide2.QtCore.QVariantAnimation.startValue()¶
- Return type:
object
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.See also
- PySide2.QtCore.QVariantAnimation.updateCurrentValue(value)¶
- Parameters:
value – object
This virtual function is called every time the animation’s current value changes. The
value
argument is the new current value.The base class implementation does nothing.
See also
- PySide2.QtCore.QVariantAnimation.valueChanged(value)¶
- Parameters:
value – object
© 2022 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 the GNU 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.