why changing QCheckBox's text color doesn't work?
I am trying to change the text color of the QCheckBox and surprisingly, nothing happens. I tried it like this first:
Code:
chk_attachments.setStyleSheet("QCheckBox { color : #767676 }");
and like this:
Code:
chk_attachments.setText("Attachments");
p=chk_attachments.palette();
chk_attachments.setPalette(p);
why my attempts are ignored by QT?
Re: why changing QCheckBox's text color doesn't work?
Code:
#include <QApplication>
#include <QWidget>
#include <QCheckBox>
#include <QVBoxLayout>
int main(int argc, char **argv)
{
c1->setCheckState(Qt::Checked);
c2->setStyleSheet("QCheckBox { color : #767676 }");
c2->setCheckState(Qt::Checked);
p.
setColor(QPalette::WindowText, Qt
::red);
c3->setPalette(p);
c3->setCheckState(Qt::Checked);
l->addWidget(c1);
l->addWidget(c2);
l->addWidget(c3);
w.setLayout(l);
w.show();
return app.exec();
}
The code above works just fine on my Linux Qt4 and Qt5.
The stylesheet approach also colours the indicator, so you probably need to also style QCheckBox::indicator.
The palette approach requires the WindowText property.
Re: why changing QCheckBox's text color doesn't work?
Well, your code does not work in my QT installation. (version 5.5, built on August 18)
I see all the text of the checkboxes in black.
Weird stuff
.
Thank you for the reply, I now know this is not the problem of my coding.