QTimeLine Class
The QTimeLine class provides a timeline for controlling animations. More…
| Header | #include <QTimeLine> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Since | 4.2 |
| Inherits | QObject |
List of all members, including inherited members
Public Types
Public Functions
| QTimeLine(int duration = 1000, QObject *parent = nullptr) | |
| ~QTimeLine() | |
| State | state() const |
| int | loopCount() const |
| void | setLoopCount(int count) |
| Direction | direction() const |
| void | setDirection(Direction direction) |
| int | duration() const |
| void | setDuration(int duration) |
| int | startFrame() const |
| void | setStartFrame(int frame) |
| int | endFrame() const |
| void | setEndFrame(int frame) |
| void | setFrameRange(int startFrame, int endFrame) |
| int | updateInterval() const |
| void | setUpdateInterval(int interval) |
| QEasingCurve | easingCurve() const |
| void | setEasingCurve(const QEasingCurve &curve) |
| int | currentTime() const |
| int | currentFrame() const |
| qreal | currentValue() const |
| int | frameForTime(int msec) const |
| virtual qreal | valueForTime(int msec) const |
Public Slots
| void | start() |
| void | resume() |
| void | stop() |
| void | setPaused(bool paused) |
| void | setCurrentTime(int msec) |
| void | toggleDirection() |
Signals
| void | valueChanged(qreal value) |
| void | frameChanged(int frame) |
| void | stateChanged(QTimeLine::State newState) |
| void | finished() |
Reimplemented Protected Functions
| void | timerEvent(QTimerEvent *event) |
Detailed Description
A QTimeLine runs for duration() milliseconds and emits valueChanged() with the progress, shaped by easingCurve(), every updateInterval() milliseconds. With a frame range it also emits frameChanged():
QTimeLine timeLine(1000);
timeLine.setFrameRange(0, 100);
QObject::connect(&timeLine, &QTimeLine::frameChanged, progressBar, &QProgressBar::setValue);
timeLine.start();
See also QEasingCurve and QTimer.
Differences from Qt
The time line advances with a timer of the event loop and the elapsed time of a QElapsedTimer. There are no bindable properties.
Member Type Documentation
enum QTimeLine::Direction
| Constant | Description |
|---|---|
QTimeLine::Forward | The current time increases with time. |
QTimeLine::Backward | The current time decreases with time. |
enum QTimeLine::State
| Constant | Description |
|---|---|
QTimeLine::NotRunning | The time line is not running. |
QTimeLine::Paused | The time line is paused; resume() or setPaused(false) continues it. |
QTimeLine::Running | The time line is running. |
Member Function Documentation
QTimeLine::QTimeLine(int duration = 1000, QObject *parent = nullptr)
Constructs a time line that runs for duration milliseconds, with the given parent. The frame range is 0 to 0 and the easing curve QEasingCurve::InOutSine.
QTimeLine::~QTimeLine()
Destroys the time line, stopping it first.
int QTimeLine::currentFrame() const
Returns the frame for the current time.
int QTimeLine::currentTime() const
Returns the current time of the time line in milliseconds, from 0 to duration().
qreal QTimeLine::currentValue() const
Returns the value for the current time.
Direction QTimeLine::direction() const
Returns the direction of the time line.
See also setDirection() and toggleDirection().
int QTimeLine::duration() const
Returns the duration of one loop in milliseconds.
QEasingCurve QTimeLine::easingCurve() const
Returns the easing curve that shapes the value of the time line.
This function was introduced in 4.6.
int QTimeLine::endFrame() const
Returns the last frame of the frame range.
void QTimeLine::finished()
This signal is emitted when the time line finishes, that is, when it reaches its end after the last loop. It is not emitted by stop().
void QTimeLine::frameChanged(int frame)
This signal is emitted when the current frame changes, with the new frame.
See also setFrameRange().
int QTimeLine::frameForTime(int msec) const
Returns the frame for the time msec: the frame range scaled by valueForTime(), rounded toward the start frame when running forward and away from it when running backward.
int QTimeLine::loopCount() const
Returns the number of times the time line runs before it finishes, 0 meaning forever. The default is 1.
See also setLoopCount().
void QTimeLine::resume()
Resumes the time line from its current time. Does nothing, with a warning, if it is already running.
void QTimeLine::setCurrentTime(int msec)
Sets the current time to msec, measured from the start of the current loop in the forward direction, and emits valueChanged() and frameChanged() as needed. A time past the end of the loop moves on to the next loops; after the last loop the time line stops and emits finished().
void QTimeLine::setDirection(Direction direction)
Sets the direction of the time line to direction. A running time line continues from its current time in the new direction.
void QTimeLine::setDuration(int duration)
Sets the duration of one loop to duration milliseconds, which must be positive.
void QTimeLine::setEasingCurve(const QEasingCurve &curve)
Sets the easing curve to curve.
This function was introduced in 4.6.
void QTimeLine::setEndFrame(int frame)
Sets the last frame of the frame range to frame.
void QTimeLine::setFrameRange(int startFrame, int endFrame)
Sets the frame range to startFrame to endFrame.
See also frameForTime() and frameChanged().
void QTimeLine::setLoopCount(int count)
Sets the number of loops to count; 0 makes the time line loop forever.
void QTimeLine::setPaused(bool paused)
Pauses the time line if paused is true, or resumes it if paused is false and it is paused.
void QTimeLine::setStartFrame(int frame)
Sets the first frame of the frame range to frame.
void QTimeLine::setUpdateInterval(int interval)
Sets the update interval to interval milliseconds. A running time line uses it from the next start or resume.
void QTimeLine::start()
Starts the time line from its beginning (from duration() when running backward). Does nothing, with a warning, if it is already running.
int QTimeLine::startFrame() const
Returns the first frame of the frame range.
State QTimeLine::state() const
Returns the state of the time line.
void QTimeLine::stateChanged(QTimeLine::State newState)
This signal is emitted when the state of the time line changes, with the new state newState.
void QTimeLine::stop()
Stops the time line, keeping its current time. finished() is not emitted.
void QTimeLine::timerEvent(QTimerEvent *event)
Reimplements QObject::timerEvent().
void QTimeLine::toggleDirection()
Reverses the direction of the time line.
See also setDirection().
int QTimeLine::updateInterval() const
Returns the interval in milliseconds between updates while the time line runs. The default is 40, 25 updates a second.
void QTimeLine::valueChanged(qreal value)
This signal is emitted at regular intervals while the time line runs, and when the current time changes, with the new value.
See also valueForTime() and updateInterval().
qreal QTimeLine::valueForTime(int msec) const
Returns the value for the time msec: the easing curve applied to the progress msec / duration(), clamped to the range 0 to 1. Reimplement it for a custom shape.