本文介绍了如何在PyQt5中更改QButtonGroup的颜色属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PyQt5中更改按钮组对象的按钮颜色.我尝试过

I want to change the color of the button of a button group object in PyQt5. I tried

QButtonGroup.setStyleSheet("""
                              QButtonGroup
                                {
                                        background-color: rgb(255, 255,255);
                                }
                                """
                                )

但是没有这样的功能.如果有人可以(在Python或C ++中)提供帮助,我将不胜感激

But there is no such a function. I would appreciate if anyone can help (either in Python or in C++ )

推荐答案

根据 Qt文档:

因此,您不能为其设置样式表.也许您想要QGroupBox?这是一个示例:

Therefore, you cannot set a stylesheet to it. Maybe you want a QGroupBox? Here is an example:

import sys
import PyQt5.QtWidgets as QtWidgets

def window():
    app = QtWidgets.QApplication(sys.argv)
    w = QtWidgets.QWidget()
    w.setWindowTitle('Hello')
    w.setGeometry(100,100,200,100)
    g = QtWidgets.QGroupBox(w)
    layout = QtWidgets.QVBoxLayout()
    b = QtWidgets.QPushButton(w)
    b.setText("Hello World!")
    b1 = QtWidgets.QPushButton(w)
    b1.setText("Hello SO!")
    layout.addWidget(b)
    layout.addWidget(b1)
    g.setLayout(layout)
    w.setStyleSheet("""
        QGroupBox { background-color: rgb(255, 255,255);
        } """)
    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    window()

这篇关于如何在PyQt5中更改QButtonGroup的颜色属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:18
查看更多