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?

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 10 Aug 2020, 07:10 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 1 Reply Last reply 10 Aug 2020, 07:17
    0
    • B Babs
      10 Aug 2020, 07:10

      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 Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 10 Aug 2020, 07:17 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 10 Aug 2020, 07:25
      1
      • J J.Hilk
        10 Aug 2020, 07:17

        @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 10 Aug 2020, 07:25 last edited by
        #3

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

        J 1 Reply Last reply 10 Aug 2020, 07:28
        0
        • B Babs
          10 Aug 2020, 07:25

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

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 10 Aug 2020, 07:28 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 10 Aug 2020, 07:29
          1
          • J J.Hilk
            10 Aug 2020, 07:28

            @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 10 Aug 2020, 07:29 last edited by
            #5

            @J-Hilk thank you

            1 Reply Last reply
            0

            2/5

            10 Aug 2020, 07:17

            • Login

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