AnimatedSprite QML Type

Draws a sprite animation. More...

Import Statement: import QtQuick
Since: Qt Quick Ultralite 2.4





Detailed Description

AnimatedSprite renders and controls animations that are provided as multiple frames in one image file. You can play it either at a fixed speed, or manually advance and control the progress.

Consider the following sprite sheet:

It can be divided up into four frames:

Use the following code to play each of these frames at a speed of 500 milliseconds per frame:

import QtQuick 2.15

AnimatedSprite {
    source: "loading.png"
    frameWidth: 64
    frameHeight: 64
    frameCount: 4
    frameDuration: 500

Property Documentation

currentFrame : int

Set this property to advance the current frame manually, when the animation is paused. You could also call the advance() method.

frameCount : int

Indicates the number of frames in the AnimatedSprite.

frameDuration : int

Duration of each frame of the animation in milliseconds. Only positive values are valid.

Changing this property while the animation is active, will restart the animation.

frameHeight : int

Set the height of a single frame in the AnimatedSprite.

frameWidth : int

Set the width of a single frame in the AnimatedSprite.

loops : int

After playing the animation this many times, the animation will automatically stop. Only positive values are valid.

Set it to AnimatedSprite.Infinite to play the animation infinitely.

Default is AnimatedSprite.Infinite.

running : bool

Indicates whether the animation is playing or not.

Default is true

source : string

The image source for the animation.

Specifying the frame size of the image source with ImageFiles.MCU.resourceAnimatedSpriteFrameWidth and ImageFiles.MCU.resourceAnimatedSpriteFrameHeight enables resource optimization by splitting the image into frame sequences and sharing common parts between them.

See also Managing Resources.

Signal Documentation


This signal is emitted when the sprite animation completes.

It is not emitted if either the running property is set to false or the loops property is set to AnimatedSprite.Infinite.

Note: The corresponding handler is onFinished.

Method Documentation


Advances the sprite animation by one frame.


Restarts the sprite animation.


Starts the sprite animation. If the animation is already running, calling this method has no effect.


Stops the sprite animation. If the animation is not running, calling this method has no effect.

Available under certain Qt licenses.
Find out more.