Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Clear and print text loop
QtWS25 Last Chance

Clear and print text loop

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 223 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MarkkyboyM Offline
    MarkkyboyM Offline
    Markkyboy
    wrote on last edited by Markkyboy
    #1

    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

    Don't just sit there standing around, pick up a shovel and sweep up!

    I live by the sea, not in it.

    jeremy_kJ 1 Reply Last reply
    0
    • MarkkyboyM 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

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      @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 and printer.text? Also, at least one error has been introduced in copying it over. The original stopped the timer when text === 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
          }
      }
      

      Asking a question about code? http://eel.is/iso-c++/testcase/

      MarkkyboyM 1 Reply Last reply
      0
      • jeremy_kJ jeremy_k

        @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 and printer.text? Also, at least one error has been introduced in copying it over. The original stopped the timer when text === 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
            }
        }
        
        MarkkyboyM Offline
        MarkkyboyM Offline
        Markkyboy
        wrote on last edited by
        #3

        @jeremy_k - Thank you. I got tired, I got muddled. I shouldn't have posted the garbage in my original thread.

        Don't just sit there standing around, pick up a shovel and sweep up!

        I live by the sea, not in it.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved