Qt Forum

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

    Forum Updated on Feb 6th

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

    General and Desktop
    5
    7
    3076
    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.
    • S
      Sriu1 last edited by

      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.

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Sriu1 last edited by

        @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 Reply Quote 2
        • S
          Sriu1 last edited by 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.

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Sriu1 last edited by JonB

            @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 Reply Quote 3
            • P
              PoonamGupta last edited by PoonamGupta

              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 Reply Quote 0
              • Roy44
                Roy44 last edited by

                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 Reply Quote 0
                • M
                  MrShawn last edited by

                  Try

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