如何用pyqt实现可检查按钮列表



我想实现单选按钮列表,但单选按钮不应该有圆圈,如果选中了单选按钮,则背景颜色与其他按钮不同。就像这张照片一样。(https://i.stack.imgur.com/LsOeE.png)

我想我可以使用单选按钮或选项卡,但我不知道如何更改这些东西的样式。告诉我一个具有类似逻辑的小部件,或者如何更改单选按钮/选项卡的样式。

如果你不需要一个单选按钮的圆圈,那么你可能根本不需要单选按钮。

相反,将标准的QPushButtons(或QToolButtons(与setCheckable(True)一起使用,并将它们添加到QButtonGroup中。

win = QWidget()
win.setStyleSheet('''
QPushButton[checkable="true"]::checked {
background: red;
}
''')
layout = QHBoxLayout(win)
group = QButtonGroup()
for title in 'cdefgh':
button = QPushButton(title)
layout.addWidget(button)
button.setCheckable(True)
group.addButton(button)
group.buttons()[0].setChecked(True)

i设置css规则:

css = '''
QRadioButton::indicator {
image: none;
}
QRadioButton::checked
{
background-color : red;   
}
'''
radioButton.setStyleSheet(css)

最新更新