Skip to content

Instantly share code, notes, and snippets.

@mottosso
Last active January 3, 2024 09:40
Show Gist options
  • Select an option

  • Save mottosso/ec8b4f0eda31e62444e8 to your computer and use it in GitHub Desktop.

Select an option

Save mottosso/ec8b4f0eda31e62444e8 to your computer and use it in GitHub Desktop.
Animated text in QML
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
}
}
}
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
}
}
}
@bm777
Copy link

bm777 commented Nov 1, 2021

Thank you dude, it worked for me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment