6.0.0-rc4Source

QTimeLine Class

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

Header#include <QTimeLine>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since4.2
InheritsQObject

List of all members, including inherited members

Public Types

enumState
enumDirection

Public Functions

QTimeLine(int duration = 1000, QObject *parent = nullptr)
~QTimeLine()
Statestate() const
intloopCount() const
voidsetLoopCount(int count)
Directiondirection() const
voidsetDirection(Direction direction)
intduration() const
voidsetDuration(int duration)
intstartFrame() const
voidsetStartFrame(int frame)
intendFrame() const
voidsetEndFrame(int frame)
voidsetFrameRange(int startFrame, int endFrame)
intupdateInterval() const
voidsetUpdateInterval(int interval)
QEasingCurveeasingCurve() const
voidsetEasingCurve(const QEasingCurve &curve)
intcurrentTime() const
intcurrentFrame() const
qrealcurrentValue() const
intframeForTime(int msec) const
virtual qrealvalueForTime(int msec) const

Public Slots

voidstart()
voidresume()
voidstop()
voidsetPaused(bool paused)
voidsetCurrentTime(int msec)
voidtoggleDirection()

Signals

voidvalueChanged(qreal value)
voidframeChanged(int frame)
voidstateChanged(QTimeLine::State newState)
voidfinished()

Reimplemented Protected Functions

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

ConstantDescription
QTimeLine::ForwardThe current time increases with time.
QTimeLine::BackwardThe current time decreases with time.

enum QTimeLine::State

ConstantDescription
QTimeLine::NotRunningThe time line is not running.
QTimeLine::PausedThe time line is paused; resume() or setPaused(false) continues it.
QTimeLine::RunningThe time line is running.

Member Function Documentation

[explicit] 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.

[override] 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.

[signal] 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().

[signal] 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().

[slot] void QTimeLine::resume()

Resumes the time line from its current time. Does nothing, with a warning, if it is already running.

[slot] 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.

[slot] 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.

[slot] 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.

See also resume() and stop().

int QTimeLine::startFrame() const

Returns the first frame of the frame range.

State QTimeLine::state() const

Returns the state of the time line.

[signal] void QTimeLine::stateChanged(QTimeLine::State newState)

This signal is emitted when the state of the time line changes, with the new state newState.

[slot] void QTimeLine::stop()

Stops the time line, keeping its current time. finished() is not emitted.

[override, protected] void QTimeLine::timerEvent(QTimerEvent *event)

Reimplements QObject::timerEvent().

[slot] 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.

[signal] 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().

[virtual] 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.