更改 PySide QGroupBox 复选框图像 [英] Change PySide QGroupBox checkbox image

查看:54
本文介绍了更改 PySide QGroupBox 复选框图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改与 QGroupBox 复选框一起显示的图像(或图标?),即:

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

特别是,我想将选中"时显示的图像更改为图像images/custom_checked.png",将鼠标悬停时显示的图像更改为images/custom_hover.png".我认为这可以使用 StyleSheets 来完成,但我没有做任何工作.

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.

以下代码会在选中复选框时更改复选框图像

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

推荐答案

你必须把每一个你想改变的东西"分开:

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

这篇关于更改 PySide QGroupBox 复选框图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆