QTimeLine¶
The QTimeLine
class provides a timeline for controlling animations. More…

Synopsis¶
Functions¶
def
currentFrame
()def
currentTime
()def
currentValue
()def
direction
()def
duration
()def
easingCurve
()def
endFrame
()def
frameForTime
(msec)def
loopCount
()def
resume
()def
setCurrentTime
(msec)def
setDirection
(direction)def
setDuration
(duration)def
setEasingCurve
(curve)def
setEndFrame
(frame)def
setFrameRange
(startFrame, endFrame)def
setLoopCount
(count)def
setPaused
(paused)def
setStartFrame
(frame)def
setUpdateInterval
(interval)def
start
()def
startFrame
()def
state
()def
stop
()def
toggleDirection
()def
updateInterval
()
Virtual functions¶
def
valueForTime
(msec)
Detailed Description¶
It’s most commonly used to animate a GUI control by calling a slot periodically. You can construct a timeline by passing its duration in milliseconds to QTimeLine
‘s constructor. The timeline’s duration describes for how long the animation will run. Then you set a suitable frame range by calling setFrameRange()
. Finally connect the frameChanged()
signal to a suitable slot in the widget you wish to animate (for example, setValue()
in QProgressBar
). When you proceed to calling start()
, QTimeLine
will enter Running state, and start emitting frameChanged()
at regular intervals, causing your widget’s connected property’s value to grow from the lower end to the upper and of your frame range, at a steady rate. You can specify the update interval by calling setUpdateInterval()
. When done, QTimeLine
enters NotRunning
state, and emits finished()
.
Example:
... progressBar = QProgressBar(self) progressBar.setRange(0, 100) # Construct a 1-second timeline with a frame range of 0 - 100 timeLine = QTimeLine(1000, self) timeLine.setFrameRange(0, 100) timeLine.frameChanged[int].connect(progressBar.setValue) # Clicking the push button will start the progress bar animation pushButton = QPushButton(QObject.tr("Start animation"), self) pushButton.clicked.connect(timeLine.start) ...
By default the timeline runs once, from its beginning to its end, upon which you must call start()
again to restart from the beginning. To make the timeline loop, you can call setLoopCount()
, passing the number of times the timeline should run before finishing. The direction can also be changed, causing the timeline to run backward, by calling setDirection()
. You can also pause and unpause the timeline while it’s running by calling setPaused()
. For interactive control, the setCurrentTime()
function is provided, which sets the time position of the time line directly. Although most useful in NotRunning
state (e.g., connected to a valueChanged()
signal in a QSlider
), this function can be called at any time.
The frame interface is useful for standard widgets, but QTimeLine
can be used to control any type of animation. The heart of QTimeLine
lies in the valueForTime()
function, which generates a value between 0 and 1 for a given time. This value is typically used to describe the steps of an animation, where 0 is the first step of an animation, and 1 is the last step. When running, QTimeLine
generates values between 0 and 1 by calling valueForTime()
and emitting valueChanged()
. By default, valueForTime()
applies an interpolation algorithm to generate these value. You can choose from a set of predefined timeline algorithms by calling setEasingCurve()
.
Note that, by default, QTimeLine
uses InOutSine
, which provides a value that grows slowly, then grows steadily, and finally grows slowly. For a custom timeline, you can reimplement valueForTime()
, in which case QTimeLine
‘s easingCurve
property is ignored.
See also
QProgressBar
QProgressDialog
-
class
PySide6.QtCore.
QTimeLine
([duration=1000[, parent=None]])¶ - Parameters
duration – int
parent –
PySide6.QtCore.QObject
Constructs a timeline with a duration of duration
milliseconds. parent
is passed to QObject
‘s constructor. The default duration is 1000 milliseconds.
-
PySide6.QtCore.QTimeLine.
State
¶
This enum describes the state of the timeline.
Constant
Description
QTimeLine.NotRunning
The timeline is not running. This is the initial state of
QTimeLine
, and the stateQTimeLine
reenters when finished. The current time, frame and value remain unchanged until eithersetCurrentTime()
is called, or the timeline is started by callingstart()
.QTimeLine.Paused
The timeline is paused (i.e., temporarily suspended). Calling
setPaused
(false) will resume timeline activity.QTimeLine.Running
The timeline is running. While control is in the event loop,
QTimeLine
will update its current time at regular intervals, emittingvalueChanged()
andframeChanged()
when appropriate.See also
state()
stateChanged()
-
PySide6.QtCore.QTimeLine.
Direction
¶
This enum describes the direction of the timeline when in Running
state.
Constant
Description
QTimeLine.Forward
The current time of the timeline increases with time (i.e., moves from 0 and towards the end / duration).
QTimeLine.Backward
The current time of the timeline decreases with time (i.e., moves from the end / duration and towards 0).
See also
-
PySide6.QtCore.QTimeLine.
currentFrame
()¶ - Return type
int
Returns the frame corresponding to the current time.
See also
-
PySide6.QtCore.QTimeLine.
currentTime
()¶ - Return type
int
See also
-
PySide6.QtCore.QTimeLine.
currentValue
()¶ - Return type
float
Returns the value corresponding to the current time.
See also
-
PySide6.QtCore.QTimeLine.
direction
()¶ - Return type
See also
-
PySide6.QtCore.QTimeLine.
duration
()¶ - Return type
int
See also
-
PySide6.QtCore.QTimeLine.
easingCurve
()¶ - Return type
See also
-
PySide6.QtCore.QTimeLine.
endFrame
()¶ - Return type
int
Returns the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1).
See also
-
PySide6.QtCore.QTimeLine.
frameForTime
(msec)¶ - Parameters
msec – int
- Return type
int
Returns the frame corresponding to the time msec
. This value is calculated using a linear interpolation of the start and end frame, based on the value returned by valueForTime()
.
See also
-
PySide6.QtCore.QTimeLine.
loopCount
()¶ - Return type
int
See also
-
PySide6.QtCore.QTimeLine.
resume
()¶
Resumes the timeline from the current time. QTimeLine
will reenter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals.
In contrast to start()
, this function does not restart the timeline before it resumes.
See also
start()
updateInterval()
frameChanged()
valueChanged()
-
PySide6.QtCore.QTimeLine.
setCurrentTime
(msec)¶ - Parameters
msec – int
See also
-
PySide6.QtCore.QTimeLine.
setDuration
(duration)¶ - Parameters
duration – int
See also
-
PySide6.QtCore.QTimeLine.
setEasingCurve
(curve)¶ - Parameters
curve –
PySide6.QtCore.QEasingCurve
See also
-
PySide6.QtCore.QTimeLine.
setEndFrame
(frame)¶ - Parameters
frame – int
Sets the end frame, which is the frame corresponding to the end of the timeline (i.e., the frame for which the current value is 1), to frame
.
See also
-
PySide6.QtCore.QTimeLine.
setFrameRange
(startFrame, endFrame)¶ - Parameters
startFrame – int
endFrame – int
Sets the timeline’s frame counter to start at startFrame
, and end and endFrame
. For each time value, QTimeLine
will find the corresponding frame when you call currentFrame()
or frameForTime()
by interpolating, using the return value of valueForTime()
.
When in Running state, QTimeLine
also emits the frameChanged()
signal when the frame changes.
See also
-
PySide6.QtCore.QTimeLine.
setLoopCount
(count)¶ - Parameters
count – int
See also
-
PySide6.QtCore.QTimeLine.
setPaused
(paused)¶ - Parameters
paused – bool
If paused
is true, the timeline is paused, causing QTimeLine
to enter Paused state. No updates will be signaled until either start()
or (false) is called. If paused
is false, the timeline is resumed and continues where it left.
-
PySide6.QtCore.QTimeLine.
setStartFrame
(frame)¶ - Parameters
frame – int
Sets the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0), to frame
.
See also
-
PySide6.QtCore.QTimeLine.
setUpdateInterval
(interval)¶ - Parameters
interval – int
See also
-
PySide6.QtCore.QTimeLine.
start
()¶
Starts the timeline. QTimeLine
will enter Running state, and once it enters the event loop, it will update its current time, frame and value at regular intervals. The default interval is 40 ms (i.e., 25 times per second). You can change the update interval by calling setUpdateInterval()
.
The timeline will start from position 0, or the end if going backward. If you want to resume a stopped timeline without restarting, you can call resume()
instead.
See also
resume()
updateInterval()
frameChanged()
valueChanged()
-
PySide6.QtCore.QTimeLine.
startFrame
()¶ - Return type
int
Returns the start frame, which is the frame corresponding to the start of the timeline (i.e., the frame for which the current value is 0).
See also
Returns the state of the timeline.
See also
-
PySide6.QtCore.QTimeLine.
stop
()¶
Stops the timeline, causing QTimeLine
to enter NotRunning
state.
See also
-
PySide6.QtCore.QTimeLine.
toggleDirection
()¶
Toggles the direction of the timeline. If the direction was Forward, it becomes Backward, and vice verca.
See also
-
PySide6.QtCore.QTimeLine.
updateInterval
()¶ - Return type
int
See also
-
PySide6.QtCore.QTimeLine.
valueForTime
(msec)¶ - Parameters
msec – int
- Return type
float
Returns the timeline value for the time msec
. The returned value, which varies depending on the curve shape, is always between 0 and 1. If msec
is 0, the default implementation always returns 0.
Reimplement this function to provide a custom curve shape for your timeline.
See also
© 2021 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.