Change PySide QGroupBox checkbox image

自作多情 提交于 2019-12-13 06:49:59

问题


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

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);}')
                  )

回答1:


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);}'


来源:https://stackoverflow.com/questions/38155287/change-pyside-qgroupbox-checkbox-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!