C

Qt Quick Ultralite sprite_animations Example

/****************************************************************************** ** ** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
import QtQuick 2.15 Rectangle { color: "black" AnimatedSprite { id: sprite anchors.centerIn: parent source: "qt-image-sequence.png" frameDuration: 80 frameCount: 16 frameWidth: 180 frameHeight: 160 loops: AnimatedSprite.Infinite onFinished: { txtMsg.text = "Finished" } onRunningChanged: { if (sprite.running) { txtMsg.text = "" } } MouseArea { anchors.fill: parent onClicked: { if (sprite.running) { sprite.stop() } else { sprite.start() } } } } Column { id: spriteInfo anchors.top: parent.top anchors.left: parent.left anchors.margins: 16 spacing: 4 Text { id: txtFrameNo text: "frame: " + (sprite.currentFrame + 1) + " / " + sprite.frameCount font.pixelSize: 14 color: "white" } Text { id: txtDuration text: "duration: " + sprite.frameDuration font.pixelSize: 14 color: "white" } Text { id: txtMsg font.pixelSize: 14 text: "" color: "white" } } ToggleButton { id: toggleLoops width: parent.width / 4 height: parent.height / 9 anchors.right: parent.right anchors.top: parent.top anchors.margins: 8 checkedText: "Infinite" uncheckedText: "Once" onCheckedChanged: { if (toggleLoops.checked) { sprite.loops = AnimatedSprite.Infinite } else { sprite.loops = 1 } } } }