![]() |
Qt 6.x
The Qt SDK
|
The QGraphicsItemAnimation class provides simple animation support for QGraphicsItem. More...
#include <qgraphicsitemanimation.h>
Public Slots | |
void | setStep (qreal x) |
Sets the current step value for the animation, causing the transformations scheduled at this step to be performed. | |
![]() | |
void | deleteLater () |
\threadsafe | |
Public Member Functions | |
QGraphicsItemAnimation (QObject *parent=nullptr) | |
Constructs an animation object with the given parent. | |
virtual | ~QGraphicsItemAnimation () |
Destroys the animation object. | |
QGraphicsItem * | item () const |
Returns the item on which the animation object operates. | |
void | setItem (QGraphicsItem *item) |
Sets the specified item to be used in the animation. | |
QTimeLine * | timeLine () const |
Returns the timeline object used to control the rate at which the animation occurs. | |
void | setTimeLine (QTimeLine *timeLine) |
Sets the timeline object used to control the rate of animation to the timeLine specified. | |
QPointF | posAt (qreal step) const |
Returns the position of the item at the given step value. | |
QList< QPair< qreal, QPointF > > | posList () const |
Returns all explicitly inserted positions. | |
void | setPosAt (qreal step, const QPointF &pos) |
Sets the position of the item at the given step value to the point specified. | |
QTransform | transformAt (qreal step) const |
Returns the transform used for the item at the specified step value. | |
qreal | rotationAt (qreal step) const |
Returns the angle at which the item is rotated at the specified step value. | |
QList< QPair< qreal, qreal > > | rotationList () const |
Returns all explicitly inserted rotations. | |
void | setRotationAt (qreal step, qreal angle) |
Sets the rotation of the item at the given step value to the angle specified. | |
qreal | xTranslationAt (qreal step) const |
Returns the horizontal translation of the item at the specified step value. | |
qreal | yTranslationAt (qreal step) const |
Returns the vertical translation of the item at the specified step value. | |
QList< QPair< qreal, QPointF > > | translationList () const |
Returns all explicitly inserted translations. | |
void | setTranslationAt (qreal step, qreal dx, qreal dy) |
Sets the translation of the item at the given step value using the horizontal and vertical coordinates specified by dx and dy. | |
qreal | verticalScaleAt (qreal step) const |
Returns the vertical scale for the item at the specified step value. | |
qreal | horizontalScaleAt (qreal step) const |
Returns the horizontal scale for the item at the specified step value. | |
QList< QPair< qreal, QPointF > > | scaleList () const |
Returns all explicitly inserted scales. | |
void | setScaleAt (qreal step, qreal sx, qreal sy) |
Sets the scale of the item at the given step value using the horizontal and vertical scale factors specified by sx and sy. | |
qreal | verticalShearAt (qreal step) const |
Returns the vertical shear for the item at the specified step value. | |
qreal | horizontalShearAt (qreal step) const |
Returns the horizontal shear for the item at the specified step value. | |
QList< QPair< qreal, QPointF > > | shearList () const |
Returns all explicitly inserted shears. | |
void | setShearAt (qreal step, qreal sh, qreal sv) |
Sets the shear of the item at the given step value using the horizontal and vertical shear factors specified by sh and sv. | |
void | clear () |
Clears the scheduled transformations used for the animation, but retains the item and timeline. | |
![]() | |
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< QString > | bindableObjectName () |
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). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
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::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), 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 (const QString &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 > | |
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 QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () 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 . | |
Protected Member Functions | |
virtual void | beforeAnimationStep (qreal step) |
This method is meant to be overridden by subclassed that needs to execute additional code before a new step takes place. | |
virtual void | afterAnimationStep (qreal step) |
This method is meant to be overridden in subclasses that need to execute additional code after a new step has taken place. | |
![]() | |
QObject * | sender () 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) | |
Additional Inherited Members | |
![]() | |
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. | |
![]() | |
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) |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QGraphicsItemAnimation class provides simple animation support for QGraphicsItem.
\inmodule QtWidgets
The QGraphicsItemAnimation class animates a QGraphicsItem. You can schedule changes to the item's transformation matrix at specified steps. The QGraphicsItemAnimation class has a current step value. When this value changes the transformations scheduled at that step are performed. The current step of the animation is set with the setStep()
function.
QGraphicsItemAnimation will do a simple linear interpolation between the nearest adjacent scheduled changes to calculate the matrix. For instance, if you set the position of an item at values 0.0 and 1.0, the animation will show the item moving in a straight line between these positions. The same is true for scaling and rotation.
It is usual to use the class with a QTimeLine. The timeline's \l{QTimeLine::}{valueChanged()} signal is then connected to the setStep()
slot. For example, you can set up an item for rotation by calling setRotationAt()
for different step values. The animations timeline is set with the setTimeLine() function.
An example animation with a timeline follows:
Note that steps lie between 0.0 and 1.0. It may be necessary to use \l{QTimeLine::}{setUpdateInterval()}. The default update interval is 40 ms. A scheduled transformation cannot be removed when set, so scheduling several transformations of the same kind (e.g., rotations) at the same step is not recommended.
Definition at line 20 of file qgraphicsitemanimation.h.
Constructs an animation object with the given parent.
Definition at line 157 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::q.
|
virtual |
Destroys the animation object.
Definition at line 166 of file qgraphicsitemanimation.cpp.
This method is meant to be overridden in subclasses that need to execute additional code after a new step has taken place.
The animation step is provided for use in cases where the action depends on its value.
Definition at line 540 of file qgraphicsitemanimation.cpp.
References Q_UNUSED.
Referenced by setStep().
This method is meant to be overridden by subclassed that needs to execute additional code before a new step takes place.
The animation step is provided for use in cases where the action depends on its value.
Definition at line 527 of file qgraphicsitemanimation.cpp.
References Q_UNUSED.
Referenced by setStep().
void QGraphicsItemAnimation::clear | ( | ) |
Clears the scheduled transformations used for the animation, but retains the item and timeline.
Definition at line 475 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::horizontalScale, QGraphicsItemAnimationPrivate::horizontalShear, QGraphicsItemAnimationPrivate::rotation, QGraphicsItemAnimationPrivate::verticalScale, QGraphicsItemAnimationPrivate::verticalShear, QGraphicsItemAnimationPrivate::xPosition, QGraphicsItemAnimationPrivate::xTranslation, QGraphicsItemAnimationPrivate::yPosition, and QGraphicsItemAnimationPrivate::yTranslation.
Returns the horizontal scale for the item at the specified step value.
Definition at line 387 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::horizontalScale, and QGraphicsItemAnimationPrivate::linearValueForStep().
Referenced by transformAt().
Returns the horizontal shear for the item at the specified step value.
Definition at line 437 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::horizontalShear, and QGraphicsItemAnimationPrivate::linearValueForStep().
Referenced by transformAt().
QGraphicsItem * QGraphicsItemAnimation::item | ( | ) | const |
Returns the item on which the animation object operates.
Definition at line 176 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::item.
Referenced by setItem().
Returns the position of the item at the given step value.
Definition at line 226 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), QGraphicsItemAnimationPrivate::startPos, QPointF::x(), QGraphicsItemAnimationPrivate::xPosition, QPointF::y(), and QGraphicsItemAnimationPrivate::yPosition.
Referenced by setStep().
Returns all explicitly inserted positions.
Definition at line 251 of file qgraphicsitemanimation.cpp.
References i, list, QList< T >::reserve(), QGraphicsItemAnimationPrivate::xPosition, and QGraphicsItemAnimationPrivate::yPosition.
Returns the angle at which the item is rotated at the specified step value.
Definition at line 288 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), and QGraphicsItemAnimationPrivate::rotation.
Referenced by transformAt().
Returns all explicitly inserted rotations.
Definition at line 309 of file qgraphicsitemanimation.cpp.
References i, list, QList< T >::reserve(), and QGraphicsItemAnimationPrivate::rotation.
Returns all explicitly inserted scales.
Definition at line 410 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::horizontalScale, i, list, QList< T >::reserve(), and QGraphicsItemAnimationPrivate::verticalScale.
void QGraphicsItemAnimation::setItem | ( | QGraphicsItem * | item | ) |
Sets the specified item to be used in the animation.
Definition at line 186 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::item, item(), QGraphicsItem::pos(), and QGraphicsItemAnimationPrivate::startPos.
Sets the position of the item at the given step value to the point specified.
Definition at line 240 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::insertUniquePair(), pos, QGraphicsItemAnimationPrivate::xPosition, and QGraphicsItemAnimationPrivate::yPosition.
Sets the rotation of the item at the given step value to the angle specified.
Definition at line 299 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::insertUniquePair(), and QGraphicsItemAnimationPrivate::rotation.
Sets the scale of the item at the given step value using the horizontal and vertical scale factors specified by sx and sy.
Definition at line 399 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::horizontalScale, QGraphicsItemAnimationPrivate::insertUniquePair(), and QGraphicsItemAnimationPrivate::verticalScale.
Sets the shear of the item at the given step value using the horizontal and vertical shear factors specified by sh and sv.
Definition at line 449 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::horizontalShear, QGraphicsItemAnimationPrivate::insertUniquePair(), and QGraphicsItemAnimationPrivate::verticalShear.
Sets the current step value for the animation, causing the transformations scheduled at this step to be performed.
Definition at line 494 of file qgraphicsitemanimation.cpp.
References afterAnimationStep(), beforeAnimationStep(), check_step_valid(), QGraphicsItemAnimationPrivate::horizontalScale, QGraphicsItemAnimationPrivate::horizontalShear, QGraphicsItemAnimationPrivate::item, posAt(), QGraphicsItemAnimationPrivate::rotation, QGraphicsItem::setPos(), QGraphicsItem::setTransform(), QGraphicsItemAnimationPrivate::startTransform, QGraphicsItemAnimationPrivate::step, transformAt(), QGraphicsItemAnimationPrivate::verticalScale, QGraphicsItemAnimationPrivate::verticalShear, QGraphicsItemAnimationPrivate::xPosition, QGraphicsItemAnimationPrivate::xTranslation, QGraphicsItemAnimationPrivate::yPosition, and QGraphicsItemAnimationPrivate::yTranslation.
Referenced by setTimeLine().
Sets the timeline object used to control the rate of animation to the timeLine specified.
Definition at line 209 of file qgraphicsitemanimation.cpp.
References QObject::connect(), setStep(), SIGNAL, SLOT, QGraphicsItemAnimationPrivate::timeLine, and timeLine().
Sets the translation of the item at the given step value using the horizontal and vertical coordinates specified by dx and dy.
Definition at line 348 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::insertUniquePair(), QGraphicsItemAnimationPrivate::xTranslation, and QGraphicsItemAnimationPrivate::yTranslation.
Returns all explicitly inserted shears.
Definition at line 460 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::horizontalShear, i, list, QList< T >::reserve(), and QGraphicsItemAnimationPrivate::verticalShear.
QTimeLine * QGraphicsItemAnimation::timeLine | ( | ) | const |
Returns the timeline object used to control the rate at which the animation occurs.
Definition at line 198 of file qgraphicsitemanimation.cpp.
References QGraphicsItemAnimationPrivate::timeLine.
Referenced by setTimeLine().
QTransform QGraphicsItemAnimation::transformAt | ( | qreal | step | ) | const |
Returns the transform used for the item at the specified step value.
Definition at line 267 of file qgraphicsitemanimation.cpp.
References check_step_valid(), horizontalScaleAt(), horizontalShearAt(), QGraphicsItemAnimationPrivate::rotation, rotationAt(), QGraphicsItemAnimationPrivate::verticalScale, verticalScaleAt(), QGraphicsItemAnimationPrivate::verticalShear, verticalShearAt(), QGraphicsItemAnimationPrivate::xTranslation, xTranslationAt(), and yTranslationAt().
Referenced by setStep().
Returns all explicitly inserted translations.
Definition at line 359 of file qgraphicsitemanimation.cpp.
References i, list, QList< T >::reserve(), QGraphicsItemAnimationPrivate::xTranslation, and QGraphicsItemAnimationPrivate::yTranslation.
Returns the vertical scale for the item at the specified step value.
Definition at line 375 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), and QGraphicsItemAnimationPrivate::verticalScale.
Referenced by transformAt().
Returns the vertical shear for the item at the specified step value.
Definition at line 426 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), and QGraphicsItemAnimationPrivate::verticalShear.
Referenced by transformAt().
Returns the horizontal translation of the item at the specified step value.
Definition at line 325 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), and QGraphicsItemAnimationPrivate::xTranslation.
Referenced by transformAt().
Returns the vertical translation of the item at the specified step value.
Definition at line 336 of file qgraphicsitemanimation.cpp.
References check_step_valid(), QGraphicsItemAnimationPrivate::linearValueForStep(), and QGraphicsItemAnimationPrivate::yTranslation.
Referenced by transformAt().