Clear and print text loop
-
wrote on 31 Mar 2024, 17:12 last edited by Markkyboy
I found some code to play with, for slicing text and displaying it like it is being typed.
It suits my needs, but I'd like the printed text to be cleared and run again repeatedly.
I've tried many different ways including another timer, but I am not getting the desired result. All suggestions welcomed.
Rectangle { width: 1500 height: 100 radius: 30 color: "dodgerblue" anchors.centerIn: parent Text { id: printer property int i property string sourceText: "How to clear and loop this text once printed?" function type() { text = sourceText.slice(0, ++i); if (text === sourceText) printer.text = text; } font.pixelSize: 72 anchors.centerIn: parent Timer { id: timer interval: 100 repeat: true running: true onTriggered: printer.type() } } }
Original code found here; https://gist.github.com/mottosso/ec8b4f0eda31e62444e8
-
I found some code to play with, for slicing text and displaying it like it is being typed.
It suits my needs, but I'd like the printed text to be cleared and run again repeatedly.
I've tried many different ways including another timer, but I am not getting the desired result. All suggestions welcomed.
Rectangle { width: 1500 height: 100 radius: 30 color: "dodgerblue" anchors.centerIn: parent Text { id: printer property int i property string sourceText: "How to clear and loop this text once printed?" function type() { text = sourceText.slice(0, ++i); if (text === sourceText) printer.text = text; } font.pixelSize: 72 anchors.centerIn: parent Timer { id: timer interval: 100 repeat: true running: true onTriggered: printer.type() } } }
Original code found here; https://gist.github.com/mottosso/ec8b4f0eda31e62444e8
wrote on 1 Apr 2024, 06:16 last edited by@Markkyboy said in Clear and print text loop:
I found some code to play with, for slicing text and displaying it like it is being typed.
The original example is confusing. What's the difference between
text
andprinter.text
? Also, at least one error has been introduced in copying it over. The original stopped the timer whentext === sourceText
. The version above does not.Here's a fixed version using an Animation:
import QtQuick 2.0 Text { id: printer property int index property string sourceText: "This is my special string." text: sourceText.slice(0, index) NumberAnimation on index { from: 0 to: printer.sourceText.length loops: Animation.Infinite duration: 1000 } }
-
@Markkyboy said in Clear and print text loop:
I found some code to play with, for slicing text and displaying it like it is being typed.
The original example is confusing. What's the difference between
text
andprinter.text
? Also, at least one error has been introduced in copying it over. The original stopped the timer whentext === sourceText
. The version above does not.Here's a fixed version using an Animation:
import QtQuick 2.0 Text { id: printer property int index property string sourceText: "This is my special string." text: sourceText.slice(0, index) NumberAnimation on index { from: 0 to: printer.sourceText.length loops: Animation.Infinite duration: 1000 } }
1/3