PySide6.QtCore.QTimeLine¶
- class QTimeLine¶
- The - QTimeLineclass provides a timeline for controlling animations. More…- Synopsis¶- Properties¶- currentTimeᅟ- The current time of the time line
- directionᅟ- The direction of the timeline when QTimeLine is in Running state
- durationᅟ- The total duration of the timeline in milliseconds
- loopCountᅟ- The number of times the timeline should loop before it’s finished
- updateIntervalᅟ- The time in milliseconds between each time QTimeLine updates its current time
 - Methods¶- def - __init__()
- def - currentFrame()
- def - currentTime()
- def - currentValue()
- def - direction()
- def - duration()
- def - easingCurve()
- def - endFrame()
- def - frameForTime()
- def - loopCount()
- def - setDirection()
- def - setDuration()
- def - setEasingCurve()
- def - setEndFrame()
- def - setFrameRange()
- def - setLoopCount()
- def - setStartFrame()
- def - startFrame()
- def - state()
- def - updateInterval()
 - Virtual methods¶- def - valueForTime()
 - Slots¶- def - resume()
- def - setCurrentTime()
- def - setPaused()
- def - start()
- def - stop()
 - Signals¶- def - finished()
- def - frameChanged()
- def - stateChanged()
- def - valueChanged()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - 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(),- QTimeLinewill 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,- QTimeLineenters- NotRunningstate, 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.connect(progressBar.setValue) # Clicking the push button will start the progress bar animation pushButton = QPushButton(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- NotRunningstate (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 - QTimeLinecan be used to control any type of animation. The heart of- QTimeLinelies 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,- QTimeLinegenerates 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, - QTimeLineuses- 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- easingCurveproperty is ignored.- See also - QProgressBarQProgressDialog- class 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 state- QTimeLinereenters when finished. The current time, frame and value remain unchanged until either- setCurrentTime()is called, or the timeline is started by calling- start().- 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, - QTimeLinewill update its current time at regular intervals, emitting- valueChanged()and- frameChanged()when appropriate.- See also 
 - class Direction¶
- This enum describes the direction of the timeline when in - Runningstate.- 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 
 - Note - Properties can be used directly when - from __feature__ import true_propertyis used or via accessor functions otherwise.- property currentTimeᅟ: int¶
 - This property holds the current time of the time line.. - When - QTimeLineis in Running state, this value is updated continuously as a function of the duration and direction of the timeline. Otherwise, it is value that was current when- stop()was called last, or the value set by setCurrentTime().- Note - You can bind other properties to currentTime, but it is not recommended setting bindings to it. As animation progresses, the currentTime is updated automatically, which cancels its bindings. - By default, this property contains a value of 0. - Access functions:
 - property directionᅟ: QTimeLine.Direction¶
 - This property holds the direction of the timeline when - QTimeLineis in- Runningstate..- This direction indicates whether the time moves from 0 towards the timeline duration, or from the value of the duration and towards 0 after - start()has been called.- Any binding of direction will be removed not only by setDirection(), but also by - toggleDirection().- By default, this property is set to - Forward.- Access functions:
 - property durationᅟ: int¶
 - This property holds the total duration of the timeline in milliseconds.. - By default, this value is 1000 (i.e., 1 second), but you can change this by either passing a duration to - QTimeLine‘s constructor, or by calling setDuration(). The duration must be larger than 0.- Note - Changing the duration does not cause the current time to be reset to zero or the new duration. You also need to call - setCurrentTime()with the desired value.- Access functions:
 - property easingCurveᅟ: QEasingCurve¶
 - Specifies the easing curve that the timeline will use. If - valueForTime()is reimplemented, this value is ignored.- See also - Access functions:
 - property loopCountᅟ: int¶
 - This property holds the number of times the timeline should loop before it’s finished.. - A loop count of 0 means that the timeline will loop forever. - By default, this property contains a value of 1. - Access functions:
 - property updateIntervalᅟ: int¶
 - This property holds the time in milliseconds between each time - QTimeLineupdates its current time..- When updating the current time, - QTimeLinewill emit- valueChanged()if the current value changed, and- frameChanged()if the frame changed.- By default, the interval is 40 ms, which corresponds to a rate of 25 updates per second. - Access functions:
 - Constructs a timeline with a duration of - durationmilliseconds.- parentis passed to- QObject‘s constructor. The default duration is 1000 milliseconds.- currentFrame()¶
- Return type:
- int 
 
 - Returns the frame corresponding to the current time. - See also - currentTime()¶
- Return type:
- int 
 - See also 
 - Getter of property - currentTimeᅟ.- currentValue()¶
- Return type:
- float 
 
 - Returns the value corresponding to the current time. - See also - direction()¶
- Return type:
 - See also 
 - Getter of property - directionᅟ.- duration()¶
- Return type:
- int 
 - See also 
 - Getter of property - durationᅟ.- easingCurve()¶
- Return type:
 - See also 
 - Getter of property - easingCurveᅟ.- 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 - finished()¶
 - This signal is emitted when - QTimeLinefinishes (i.e., reaches the end of its time line), and does not loop.- frameChanged(frame)¶
- Parameters:
- frame – int 
 
 - QTimeLineemits this signal at regular intervals when in- Runningstate, but only if the current frame changes.- frameis the current frame number.- See also - 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 - loopCount()¶
- Return type:
- int 
 - See also 
 - Getter of property - loopCountᅟ.- resume()¶
 - Resumes the timeline from the current time. - QTimeLinewill 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.- setCurrentTime(msec)¶
- Parameters:
- msec – int 
 - See also 
 - Setter of property - currentTimeᅟ.- Setter of property - directionᅟ.- setDuration(duration)¶
- Parameters:
- duration – int 
 - See also 
 - Setter of property - durationᅟ.- setEasingCurve(curve)¶
- Parameters:
- curve – - QEasingCurve
 - See also 
 - Setter of property - easingCurveᅟ.- 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 - 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,- QTimeLinewill find the corresponding frame when you call- currentFrame()or- frameForTime()by interpolating, using the return value of- valueForTime().- When in Running state, - QTimeLinealso emits the- frameChanged()signal when the frame changes.- See also - setLoopCount(count)¶
- Parameters:
- count – int 
 - See also 
 - Setter of property - loopCountᅟ.- setPaused(paused)¶
- Parameters:
- paused – bool 
 
 - If - pausedis true, the timeline is paused, causing- QTimeLineto enter Paused state. No updates will be signaled until either- start()or setPaused(false) is called. If- pausedis false, the timeline is resumed and continues where it left.- 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 - setUpdateInterval(interval)¶
- Parameters:
- interval – int 
 - See also 
 - Setter of property - updateIntervalᅟ.- start()¶
 - Starts the timeline. - QTimeLinewill 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.- 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 - This signal is emitted whenever - QTimeLine‘s state changes. The new state is- newState.- stop()¶
 - Stops the timeline, causing - QTimeLineto enter- NotRunningstate.- See also - toggleDirection()¶
 - Toggles the direction of the timeline. If the direction was Forward, it becomes Backward, and vice verca. - Existing bindings of - directionare removed.- See also - updateInterval()¶
- Return type:
- int 
 - See also 
 - Getter of property - updateIntervalᅟ.- valueChanged(x)¶
- Parameters:
- x – float 
 
 - QTimeLineemits this signal at regular intervals when in- Runningstate, but only if the current value changes.- valueis the current value.- valueis a number between 0.0 and 1.0- See also - 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- msecis 0, the default implementation always returns 0.- Reimplement this function to provide a custom curve shape for your timeline. - See also