Important: Please read the Qt Code of Conduct -

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

  • 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.

  • @Sriu1
    And what did you actually try in your stylesheet? gives the answer for Qt 5.

  • Hi
    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.

  • @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.

  • Hi

    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("); ") +

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

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

    QPalette palette = myCheckBox->palette();
        palette.setColor(WindowText, QColor(Qt::red));

  • Try

    setStylesheet("QCheckBox::QLabel {color: red;}")

Log in to reply