Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the appearance of a QT checkbox indicator

I need to change how the checkable box of a QCHeckBox looks, and not simply with CSS, but with a texture file. The closest thing I found was changing the icon parameter of the widget.

But a) it doesn't update, and b) It is located after the box, which I'm actually trying to change. Is it possible to change the checkbox itself?

like image 932
Kai Fireborn Avatar asked Dec 06 '25 08:12

Kai Fireborn


1 Answers

Confusingly, those icon properties are associated with the QAbstractButton parent class, which doesn't have the concept of a checkbox icon. So they just add an icon to the label of the button, which results in the behaviour you describe.

To change the actual checkbox icon, the best option I've found is to use a stylesheet. All the gory details are here.

In summary, something like this will do as the QCheckBox's stylesheet:

QCheckBox::indicator:unchecked {
    image: url(:/images/checkbox_unchecked.png);
}

QCheckBox::indicator:checked {
    image: url(:/images/checkbox_checked.png);
like image 158
Heath Raftery Avatar answered Dec 07 '25 23:12

Heath Raftery



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!