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. How to change the text color of the label which is in QCheckBox?
Forum Updated to NodeBB v4.3 + New Features

How to change the text color of the label which is in QCheckBox?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 5.2k 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.
  • S Offline
    S Offline
    Sriu1
    wrote on last edited by
    #1

    i want to change the text color of label inside a checkbox without creating a customised QCheckBox.Is it possible ?I tried stylesheets .Please suggest.

    JonBJ 1 Reply Last reply
    0
    • S Sriu1

      i want to change the text color of label inside a checkbox without creating a customised QCheckBox.Is it possible ?I tried stylesheets .Please suggest.

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

      @Sriu1
      And what did you actually try in your stylesheet?
      https://stackoverflow.com/a/35487195/489865 gives the answer for Qt 5.

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Sriu1
        wrote on last edited by Sriu1
        #3

        Hi
        @JonB
        I tried
        ui->myCheckbox->setStyleSheet("QCheckBox:unchecked{ color: red; }QCheckBox:checked{ color: white; }");
        Not working my background is black.

        I want only the label text to be changed.Like in the normal qlabels where we set rich text and select color.

        JonBJ 1 Reply Last reply
        0
        • S Sriu1

          Hi
          @JonB
          I tried
          ui->myCheckbox->setStyleSheet("QCheckBox:unchecked{ color: red; }QCheckBox:checked{ color: white; }");
          Not working my background is black.

          I want only the label text to be changed.Like in the normal qlabels where we set rich text and select color.

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

          @Sriu1

          • I don't see why setting color rather than background-color style would change background color.
          • The stackoverflow post is in answer to questioner's

          can somebody help me with code to change color of check box text label.

          I take that to refer to the color (foreground) of the text. However, I leave it to you.

          1 Reply Last reply
          3
          • P Offline
            P Offline
            PoonamGupta
            wrote on last edited by PoonamGupta
            #5

            Hi

            Use
            ui->mycheckbox->setstyleSheet{ QString( " QCheckBox{ color: white; }"); }

            For indicator color use :
            QString("QCheckBox::indicator { border: 1px solid #4198EF }")

            and you can use some Icon for checked check box:

            QString("QCheckBox::indicator:checked {") +
            QString("image: url(") + checkedCheckBoxIconPath() + QString("); ") +
            QString("}");

            Also check if parent widget is overriding this styles something like setStyleSheet(QWidget { color: black; });

            1 Reply Last reply
            0
            • Roy44R Offline
              Roy44R Offline
              Roy44
              wrote on last edited by
              #6

              To change the text color, you can modify the palette:

              QPalette palette = myCheckBox->palette();
                  palette.setColor(WindowText, QColor(Qt::red));
                  myCheckBox->setPalette(palette);
              
              1 Reply Last reply
              0
              • M Offline
                M Offline
                MrShawn
                wrote on last edited by
                #7

                Try

                setStylesheet("QCheckBox::QLabel {color: red;}")
                
                1 Reply Last reply
                1

                • Login

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