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. How to change color of last character in QML Text?
QtWS25 Last Chance

How to change color of last character in QML Text?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmltexttext color
5 Posts 2 Posters 2.1k 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.
  • B Offline
    B Offline
    Babs
    wrote on last edited by
    #1

    Hello,
    Is it possible to have different colors for the same QML Text component? I want a specefic color for my text last character.

    J.HilkJ 1 Reply Last reply
    0
    • B Babs

      Hello,
      Is it possible to have different colors for the same QML Text component? I want a specefic color for my text last character.

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Babs QML and Text components support rich text formatting so something like this can work:

       Text {
              anchors.fill:parent
              text: "Normal text <font color=\"#FF0000\">this part is red</font>"
          }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      B 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @Babs QML and Text components support rich text formatting so something like this can work:

         Text {
                anchors.fill:parent
                text: "Normal text <font color=\"#FF0000\">this part is red</font>"
            }
        
        B Offline
        B Offline
        Babs
        wrote on last edited by
        #3

        @J-Hilk can it work when my text are QString variables?

        J.HilkJ 1 Reply Last reply
        0
        • B Babs

          @J-Hilk can it work when my text are QString variables?

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Babs sure, you can reformat your strings to include the tags or do something like this

          Text {
                  anchors.fill:parent
                  text: "%1<font color=\"#FF0000\">%2</font>".arg(stringA).arg(stringB)
              }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          B 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @Babs sure, you can reformat your strings to include the tags or do something like this

            Text {
                    anchors.fill:parent
                    text: "%1<font color=\"#FF0000\">%2</font>".arg(stringA).arg(stringB)
                }
            
            B Offline
            B Offline
            Babs
            wrote on last edited by
            #5

            @J-Hilk thank you

            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