Standard icon for QCheckBox?
-
Hi, I am using
fusion
style and trying to change the::indicator
background colour forQCheckBox
:qApp->setStyleSheet("QCheckBox::indicator{background: red}");
It works fine but the checkbox icon is no longer shown, is there any way I can get the standard icon and reapply it there? I know I can get my own icon through resource files but I would rather stick to the standard icons.
-
If you don't want to roll your own checkbox another way could be to customize the style. There's QStyleProxy that allows you to reuse the native style and only customize the small parts you need. You could provide only the checkbox painting and leave everything else to the base implementation. Could be a good way to do it if you'd ever need anything else style related customized.
-
Standard image is drawn using the native style plugin. When you set any stylesheet on a widget you're disabling that native style and switching to the stylesheet style.
Instead of using stylesheet you could try deriving from QCheckBox and reimplementpaintEvent
to fill the background and then call base implementation to draw the checkbox image. -
@Chris-Kawa Thanks! I was hoping there would be a simpler way, like getting the native checkbox image from Qt (wherever it is stored) and applying it through the stylesheet like an image. I would use
:checked
,:unchecked
,pressed
and:indeterminate
pseudo-states. This way I would not have to create my own checkbox class. -
Style has a standardPixmap method to retrieve some pixmaps used by the style, but it doesn't seem to have an enum value for a checkbox, so you're out of luck I'm afraid.
-
If you don't want to roll your own checkbox another way could be to customize the style. There's QStyleProxy that allows you to reuse the native style and only customize the small parts you need. You could provide only the checkbox painting and leave everything else to the base implementation. Could be a good way to do it if you'd ever need anything else style related customized.
-
@Chris-Kawa Thanks! I was able to get it to work by using
QProxyStyle
.