Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multicolor text
QtWS25 Last Chance

Multicolor text

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by A Former User
    #1

    Hi

    I have a string constructed this way:

    const auto text = QString { "#%1%2%3%4" }
    			.arg(QString::number(n), -15)
    			.arg(someText, -45)
    			.arg(symbol, -2)
    			.arg(QString::number(someNumber), -5);
    

    How can I make the %3 argument to be another color?

    The text is set to a label, so if I put

    QString { "#%1%2<font color=\"red\">%3</font>%4" }
    

    all the styles of the label are gone.

    What can I do?

    K 1 Reply Last reply
    0
    • U user4592357

      Hi

      I have a string constructed this way:

      const auto text = QString { "#%1%2%3%4" }
      			.arg(QString::number(n), -15)
      			.arg(someText, -45)
      			.arg(symbol, -2)
      			.arg(QString::number(someNumber), -5);
      

      How can I make the %3 argument to be another color?

      The text is set to a label, so if I put

      QString { "#%1%2<font color=\"red\">%3</font>%4" }
      

      all the styles of the label are gone.

      What can I do?

      K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      @user4592357 Do you set the labels text for mat to rich text somewhere in you code?

      setTextFormat(Qt::TextFormat)
      
      U 1 Reply Last reply
      0
      • K kenchan

        @user4592357 Do you set the labels text for mat to rich text somewhere in you code?

        setTextFormat(Qt::TextFormat)
        
        U Offline
        U Offline
        user4592357
        wrote on last edited by
        #3

        @kenchan yeah, doesn't help

        1 Reply Last reply
        0
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          Just to be clear, you do both mean/have tried setTextFormat(Qt::RichText), right?

          K 1 Reply Last reply
          0
          • JonBJ JonB

            Just to be clear, you do both mean/have tried setTextFormat(Qt::RichText), right?

            K Offline
            K Offline
            kenchan
            wrote on last edited by
            #5

            @JNBarchan Yes that is what I meant, and of course one should pass it Qt::RichText if you want it to understand rich text.

            JonBJ 1 Reply Last reply
            0
            • K kenchan

              @JNBarchan Yes that is what I meant, and of course one should pass it Qt::RichText if you want it to understand rich text.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @kenchan
              I know, but you can never be sure here what users are actually writing in their code in these cases :) @user4592357 may be fine for this, but others sometimes aren't....

              U 1 Reply Last reply
              2
              • JonBJ JonB

                @kenchan
                I know, but you can never be sure here what users are actually writing in their code in these cases :) @user4592357 may be fine for this, but others sometimes aren't....

                U Offline
                U Offline
                user4592357
                wrote on last edited by user4592357
                #7

                @JNBarchan yes, i tried that.

                and sorry to confuse you, of course i understood. if i didn't know what he meant, i'd just ask :)

                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