Last active
January 3, 2024 09:40
-
-
Save mottosso/ec8b4f0eda31e62444e8 to your computer and use it in GitHub Desktop.
Animated text in QML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import QtQuick 2.0 | |
| /*! | |
| An alternative implementation, | |
| this one causes a binding loop for some reason. | |
| */ | |
| Rectangle { | |
| width: 500 | |
| height: 300 | |
| Text { | |
| id: printer | |
| property int index | |
| property bool isTag | |
| property string sourceText: "This is my special string." | |
| property string destinationText: "" | |
| text: sourceText.slice(0, ++index) | |
| NumberAnimation on index { | |
| to: printer.sourceText.length | |
| duration: 1000 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import QtQuick 2.0 | |
| /*! | |
| This example illustrates how to animate text | |
| using a Timer and some JavaScript. | |
| */ | |
| Rectangle { | |
| width: 500 | |
| height: 300 | |
| Text { | |
| id: printer | |
| property int i | |
| property bool isTag | |
| property string sourceText: "This is my special string." | |
| function type() { | |
| text = sourceText.slice(0, ++i); | |
| if (text === sourceText) return timer.stop() | |
| printer.text = text; | |
| } | |
| Timer { | |
| id: timer | |
| interval: 100 | |
| repeat: true | |
| running: true | |
| onTriggered: printer.type() | |
| onRunningChanged: running === false ? print("Stopped.") : null | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you dude, it worked for me :)