Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Solved How to change color of last character in QML Text?

    QML and Qt Quick
    qml text text color
    2
    5
    608
    Loading More Posts
    • 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
      Babs last edited by

      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.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @Babs last edited by

        @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

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

        B 1 Reply Last reply Reply Quote 1
        • B
          Babs @J.Hilk last edited by

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

          J.Hilk 1 Reply Last reply Reply Quote 0
          • J.Hilk
            J.Hilk Moderators @Babs last edited by

            @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

            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

            B 1 Reply Last reply Reply Quote 1
            • B
              Babs @J.Hilk last edited by

              @J-Hilk thank you

              1 Reply Last reply Reply Quote 0
              • First post
                Last post