Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQuickFrameAnimation Class Reference

#include <qquickframeanimation_p.h>

+ Inheritance diagram for QQuickFrameAnimation:
+ Collaboration diagram for QQuickFrameAnimation:

Public Slots

void start ()
 \qmlmethod QtQuick::FrameAnimation::start()
 
void stop ()
 \qmlmethod QtQuick::FrameAnimation::stop()
 
void restart ()
 \qmlmethod QtQuick::FrameAnimation::restart()
 
void pause ()
 \qmlmethod QtQuick::FrameAnimation::pause()
 
void resume ()
 \qmlmethod QtQuick::FrameAnimation::resume()
 
void reset ()
 \qmlmethod QtQuick::FrameAnimation::reset()
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void triggered ()
 
void runningChanged ()
 
void pausedChanged ()
 
void currentFrameChanged ()
 
void frameTimeChanged ()
 
void smoothFrameTimeChanged ()
 
void elapsedTimeChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QQuickFrameAnimation (QObject *parent=nullptr)
 \qmltype FrameAnimation \instantiates QQuickFrameAnimation \inqmlmodule QtQuick
 
bool isRunning () const
 \qmlsignal QtQuick::FrameAnimation::triggered()
 
void setRunning (bool running)
 
bool isPaused () const
 \qmlproperty bool QtQuick::FrameAnimation::paused
 
void setPaused (bool paused)
 
int currentFrame () const
 \qmlproperty int QtQuick::FrameAnimation::currentFrame \readonly
 
qreal frameTime () const
 \qmlproperty qreal QtQuick::FrameAnimation::frameTime \readonly
 
qreal smoothFrameTime () const
 \qmlproperty qreal QtQuick::FrameAnimation::smoothFrameTime \readonly
 
qreal elapsedTime () const
 \qmlproperty qreal QtQuick::FrameAnimation::elapsedTime \readonly
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 
- Public Member Functions inherited from QQmlParserStatus
 QQmlParserStatus ()
 
virtual ~QQmlParserStatus ()
 

Protected Member Functions

void classBegin () override
 
void componentComplete () override
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 

Properties

bool running
 
bool paused
 
int currentFrame
 
qreal frameTime
 
qreal smoothFrameTime
 
qreal elapsedTime
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Additional Inherited Members

- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Detailed Description

Definition at line 26 of file qquickframeanimation_p.h.

Constructor & Destructor Documentation

◆ QQuickFrameAnimation()

QQuickFrameAnimation::QQuickFrameAnimation ( QObject * parent = nullptr)

\qmltype FrameAnimation \instantiates QQuickFrameAnimation \inqmlmodule QtQuick

Since
6.4

Triggers a handler at every animation frame update.

A FrameAnimation can be used to trigger an action every time animations have progressed and an animation frame has been rendered. See the documentation about the \l{qtquick-visualcanvas-scenegraph.html}{Scene Graph} for in-depth information about the threaded and basic render loops.

For general animations, prefer using NumberAnimation and other Animation elements as those provide declarative way to describe the animations.

FrameAnimation on the other hand should be used for custom imperative animations and in use-cases like these: \list

  • When you need to run some code on every frame update. Or e.g. every other frame, maybe using progressive rendering.
  • When the speed / target is changing during the animation, normal QML animations can be too limiting.
  • When more accurate frame update time is needed, e.g. for fps counter. \endlist

Compared to Timer which allows to set the interval time, FrameAnimation runs always in synchronization with the animation updates. If you have used Timer with a short interval for custom animations like below, please consider switching to use FrameAnimation instead for smoother animations.

// BAD
Timer {
interval: 16
repeat: true
running: true
onTriggered: {
// Animate something
}
}
// GOOD
FrameAnimation {
running: true
onTriggered: {
// Animate something
}
}

Definition at line 146 of file qquickframeanimation.cpp.

References QAbstractAnimationJob::CurrentLoop, and d.

Member Function Documentation

◆ classBegin()

void QQuickFrameAnimation::classBegin ( )
overrideprotectedvirtual

Implements QQmlParserStatus.

Definition at line 421 of file qquickframeanimation.cpp.

References d.

◆ componentComplete()

void QQuickFrameAnimation::componentComplete ( )
overrideprotectedvirtual

Implements QQmlParserStatus.

Definition at line 430 of file qquickframeanimation.cpp.

References d.

◆ currentFrame()

int QQuickFrameAnimation::currentFrame ( ) const

\qmlproperty int QtQuick::FrameAnimation::currentFrame \readonly

This property holds the number of frame updates since the start. When the frame animation is restarted, currentFrame starts from 0.

The following example shows how to react on frame updates.

FrameAnimation {
running: true
onTriggered: {
// Run code on every frame update.
}
}

This property can also be used for rendering only every nth frame. Consider an advanced usage where the UI contains two heavy elements and to reach smooth 60fps overall frame rate, you decide to render these heavy elements at 30fps, first one on every even frames and second one on every odd frames:

FrameAnimation {
running: true
onTriggered: {
if (currentFrame % 2 == 0)
updateUIElement1();
else
updateUIElement2();
}
}

By default, frame is 0.

Definition at line 248 of file qquickframeanimation.cpp.

References d.

◆ currentFrameChanged

void QQuickFrameAnimation::currentFrameChanged ( )
signal

◆ elapsedTime()

qreal QQuickFrameAnimation::elapsedTime ( ) const

\qmlproperty qreal QtQuick::FrameAnimation::elapsedTime \readonly

This property holds the time (in seconds) since the previous start.

By default, elapsedTime is 0.

Definition at line 327 of file qquickframeanimation.cpp.

References d.

◆ elapsedTimeChanged

void QQuickFrameAnimation::elapsedTimeChanged ( )
signal

◆ frameTime()

qreal QQuickFrameAnimation::frameTime ( ) const

\qmlproperty qreal QtQuick::FrameAnimation::frameTime \readonly

This property holds the time (in seconds) since the previous frame update.

The following example shows how to use frameTime to animate item with varying speed, adjusting to screen refresh rates and possible fps drops.

Rectangle {
property real speed: 90
width: 100
height: 100
color: "red"
}
FrameAnimation {
id: frameAnimation
running: true
onTriggered: {
// Rotate the item speed-degrees / second.
rect.rotation += rect.speed * frameTime
}
}
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
QQuickItem * centerIn
rect
[4]
GLint GLsizei GLsizei height
GLenum GLuint id
[7]
GLint GLsizei width
GLuint color
[2]
QQuickAnchors * anchors(QQuickItem *item)

By default, frameTime is 0.

Definition at line 285 of file qquickframeanimation.cpp.

References d.

◆ frameTimeChanged

void QQuickFrameAnimation::frameTimeChanged ( )
signal

◆ isPaused()

bool QQuickFrameAnimation::isPaused ( ) const

\qmlproperty bool QtQuick::FrameAnimation::paused

If set to true, pauses the frame animation; otherwise resumes it.

paused defaults to false.

See also
pause(), resume()

Definition at line 195 of file qquickframeanimation.cpp.

References d.

◆ isRunning()

bool QQuickFrameAnimation::isRunning ( ) const

\qmlsignal QtQuick::FrameAnimation::triggered()

This signal is emitted when the FrameAnimation has progressed to a new frame.

\qmlproperty bool QtQuick::FrameAnimation::running

If set to true, starts the frame animation; otherwise stops it.

running defaults to false.

See also
stop(), start(), restart()

Definition at line 169 of file qquickframeanimation.cpp.

References d.

◆ pause

void QQuickFrameAnimation::pause ( )
slot

\qmlmethod QtQuick::FrameAnimation::pause()

Pauses the frame animation

If the frame animation is already paused or not running, calling this method has no effect. The paused property will be true following a call to pause().

Definition at line 379 of file qquickframeanimation.cpp.

References setPaused().

+ Here is the call graph for this function:

◆ pausedChanged

void QQuickFrameAnimation::pausedChanged ( )
signal

Referenced by setPaused().

+ Here is the caller graph for this function:

◆ reset

void QQuickFrameAnimation::reset ( )
slot

\qmlmethod QtQuick::FrameAnimation::reset()

Resets the frame animation properties

Calling this method resets the frame and elapsedTime to their initial values (0). This method has no effect on running or paused properties and can be called while they are true or false.

The difference between calling reset() and restart() is that reset() will always initialize the properties while restart() initializes them only at the next frame update which doesn't happen e.g. if restart() is immediately followed by pause().

Definition at line 409 of file qquickframeanimation.cpp.

References d.

◆ restart

void QQuickFrameAnimation::restart ( )
slot

\qmlmethod QtQuick::FrameAnimation::restart()

Restarts the frame animation

If the FrameAnimation is not running it will be started, otherwise it will be stopped, reset to initial state and started. The running property will be true following a call to restart().

Definition at line 366 of file qquickframeanimation.cpp.

References start(), and stop().

+ Here is the call graph for this function:

◆ resume

void QQuickFrameAnimation::resume ( )
slot

\qmlmethod QtQuick::FrameAnimation::resume()

Resumes a paused frame animation

If the frame animation is not paused or not running, calling this method has no effect. The paused property will be false following a call to resume().

Definition at line 391 of file qquickframeanimation.cpp.

References setPaused().

+ Here is the call graph for this function:

◆ runningChanged

void QQuickFrameAnimation::runningChanged ( )
signal

Referenced by setRunning().

+ Here is the caller graph for this function:

◆ setPaused()

void QQuickFrameAnimation::setPaused ( bool paused)

Definition at line 201 of file qquickframeanimation.cpp.

References d, paused, pausedChanged(), and Q_EMIT.

Referenced by pause(), resume(), and stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRunning()

void QQuickFrameAnimation::setRunning ( bool running)

Definition at line 175 of file qquickframeanimation.cpp.

References d, Q_EMIT, running, and runningChanged().

Referenced by start(), and stop().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smoothFrameTime()

qreal QQuickFrameAnimation::smoothFrameTime ( ) const

\qmlproperty qreal QtQuick::FrameAnimation::smoothFrameTime \readonly

This property holds the smoothed time (in seconds) since the previous frame update.

The following example shows how to use smoothFrameTime to show average fps.

Text {
text: "fps: " + frameAnimation.fps.toFixed(0)
}
FrameAnimation {
id: frameAnimation
property real fps: smoothFrameTime > 0 ? (1.0 / smoothFrameTime) : 0
running: true
}
QString text

By default, smoothFrameTime is 0.

Definition at line 313 of file qquickframeanimation.cpp.

References d.

◆ smoothFrameTimeChanged

void QQuickFrameAnimation::smoothFrameTimeChanged ( )
signal

◆ start

void QQuickFrameAnimation::start ( )
slot

\qmlmethod QtQuick::FrameAnimation::start()

Starts the frame animation

If the frame animation is already running, calling this method has no effect. The running property will be true following a call to start().

Definition at line 340 of file qquickframeanimation.cpp.

References setRunning().

Referenced by restart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stop

void QQuickFrameAnimation::stop ( )
slot

\qmlmethod QtQuick::FrameAnimation::stop()

Stops the frame animation

If the frame animation is not running, calling this method has no effect. Both the running and paused properties will be false following a call to stop().

Definition at line 352 of file qquickframeanimation.cpp.

References setPaused(), and setRunning().

Referenced by restart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ triggered

void QQuickFrameAnimation::triggered ( )
signal

Property Documentation

◆ currentFrame

int QQuickFrameAnimation::currentFrame
read

Definition at line 33 of file qquickframeanimation_p.h.

◆ elapsedTime

qreal QQuickFrameAnimation::elapsedTime
read

Definition at line 36 of file qquickframeanimation_p.h.

◆ frameTime

qreal QQuickFrameAnimation::frameTime
read

Definition at line 34 of file qquickframeanimation_p.h.

◆ paused

bool QQuickFrameAnimation::paused
readwrite

Definition at line 32 of file qquickframeanimation_p.h.

Referenced by setPaused().

◆ running

bool QQuickFrameAnimation::running
readwrite

Definition at line 31 of file qquickframeanimation_p.h.

Referenced by setRunning().

◆ smoothFrameTime

qreal QQuickFrameAnimation::smoothFrameTime
read

Definition at line 35 of file qquickframeanimation_p.h.


The documentation for this class was generated from the following files: