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. QLabel text color
Qt 6.11 is out! See what's new in the release blog

QLabel text color

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 12.6k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    mahd96
    wrote on last edited by
    #1

    how can i change QLabel / QtextViewer text color in its PaintEvent() ?

    Pl45m4P 1 Reply Last reply
    0
    • M mahd96

      how can i change QLabel / QtextViewer text color in its PaintEvent() ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @mahd96

      Hi.

      You can use stylesheet

      setStylesheet("color: red;");
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Why are you re-implementing the paintEvent of these widgets ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        4
        • SGaistS SGaist

          Hi,

          Why are you re-implementing the paintEvent of these widgets ?

          M Offline
          M Offline
          mahd96
          wrote on last edited by
          #4

          @SGaist I dont want to use stylesheet for some reasons.

          with paintEvent i can have runtime Theme Changing for my app.

          i know i could use QPallete but for "Theme" i should do some signal/Slot that i am avoiding!

          Pl45m4P 1 Reply Last reply
          0
          • M mahd96

            @SGaist I dont want to use stylesheet for some reasons.

            with paintEvent i can have runtime Theme Changing for my app.

            i know i could use QPallete but for "Theme" i should do some signal/Slot that i am avoiding!

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @mahd96

            You can change the color with stylesheet on runtime too


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            M 1 Reply Last reply
            2
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              In that case why not make a custom style ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • Pl45m4P Pl45m4

                @mahd96

                You can change the color with stylesheet on runtime too

                M Offline
                M Offline
                mahd96
                wrote on last edited by
                #7

                @Pl45m4
                I know that. i dont want to use stylesheet for other reasons

                JonBJ 1 Reply Last reply
                0
                • M mahd96

                  @Pl45m4
                  I know that. i dont want to use stylesheet for other reasons

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

                  @mahd96 Then do as @SGaist has suggested just above.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mahd96
                    wrote on last edited by
                    #9

                    I asked for a way to do it within painEvent() ! i can not use any other way!!

                    JonBJ 1 Reply Last reply
                    0
                    • M mahd96

                      I asked for a way to do it within painEvent() ! i can not use any other way!!

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

                      @mahd96
                      Then there is an accepted answer at https://stackoverflow.com/a/2756376/, which recommends using stylesheet but shows possibly using setPalette(), though warns it may not come out right, you'll have to try....

                      1 Reply Last reply
                      2

                      • Login

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