Search code examples
pythonpython-2.7pysideqgroupbox

Change PySide QGroupBox checkbox image


I would like to change the image (or icon?) displayed with the checkbox for a QGroupBox, i.e.:

checkbox for qgroupbox

In particular, I would like to change the image displayed when it is 'checked' to the image 'images/custom_checked.png', and the image displayed when it is hovered over to 'images/custom_hover.png'. I think this can be accomplished using StyleSheets but I have not been able to make anything work.

Edit: The following code does change the checkbox image when the checkbox is checked

class MyGroupBox(QtGui.QGroupBox):
    def __init__(self, parent):
        super(MyGroupBox, self).__init__(parent)

        self.setStyleSheet('QGroupBox::indicator:checked {image: url(images//custom_checked.png);}')

but when I add the next line to take care of the image when hovering, it only applies the hovering image and ignores the checked image (i.e., the normal checked checkbox image is present until I hover over the checkbox at which point it transitions to the custom hover image):

class MyGroupBox(QtGui.QGroupBox):
    def __init__(self, parent):
        super(MyGroupBox, self).__init__(parent)

        self.setStyleSheet('QGroupBox::indicator:checked {image: url(images//custom_checked.png);}')
        self.setStyleSheet('QGroupBox::indicator:checked:hover {image: url(images//custom_hover.png);}')
                  )

Solution

  • You have to put each 'thing' you want to change separately:

    self.setStyleSheet('QGroupBox::indicator:checked:hover {image: url(images//custom_hover.png);}'
                       'QGroupBox::indicator:checked {image: url(images//custom_delete.png);}'