[英]how to change the color properties of QButtonGroup in PyQt5?
I want to change the color of the button of a button group object in PyQt5. 我想在PyQt5中更改按钮组对象的按钮颜色。 I tried 我试过了
QButtonGroup.setStyleSheet("""
QButtonGroup
{
background-color: rgb(255, 255,255);
}
"""
)
But there is no such a function. 但是没有这样的功能。 I would appreciate if anyone can help (either in Python or in C++ ) 如果有人可以提供帮助(使用Python或C ++),我将不胜感激
According to Qt doc : 根据Qt doc :
QButtonGroup provides an abstract container into which button widgets can be placed. QButtonGroup提供了一个抽象的容器,可以在其中放置按钮小部件。 It does not provide a visual representation of this container (see QGroupBox for a container widget), but instead manages the states of each of the buttons in the group. 它不提供此容器的直观表示(有关容器小部件,请参阅QGroupBox),而是管理组中每个按钮的状态。
Therefore, you cannot set a stylesheet to it. 因此,您不能为其设置样式表。 Maybe you want a QGroupBox? 也许您想要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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.