PDA

View Full Version : Disabling the user to change QCheckBox checkstate



ChiliPalmer
26th September 2009, 16:08
Hi

I'm trying to show a bool value with a QCheckBox, that the user shouldn't be able to change, but without changing the appearance of the QCheckBox.

This is what I've got so far:


checkBox->setEnabled(false);
QPalette palette(checkBox->palette());
palette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(Qt::black));
checkBox->setPalette(palette);

That changes the text color back to black, but the checked indicator still is grey.
I tried to change it with a style-sheet:


checkBox->setStyleSheet("::indicator { border-color: black; }");
...with that the indicator isn't visible.


checkBox->setStyleSheet("::indicator { width: 12px; height: 12px; border-width: 1px; border-style: solid; border-color: black; }");
... with that it is, but it just looks weird, plus the check doesn't show.

There has to be a simpler way.
I already thought about just connecting the QCheckBox toggled(bool checked) signal to a slot connected to:


void::myClass checkBoxToggled(bool checked)
{
checkbox->setChecked(whatever I need);
}

..or something like that.

Any suggestions?

wysota
26th September 2009, 17:20
I would go for connecting the toggled() signal to a slot and resetting the value if I wanted to do it the way you want. But from user friendliness point of view, you should just disable the checkbox and accept that it changes appearance - the user should be aware that he can't change the state of the box.