gpt4 book ai didi

python - 一个窗口中的多个 QButtonGroups

转载 作者:行者123 更新时间:2023-11-28 22:58:36 30 4
gpt4 key购买 nike

我正在使用 PyQt 编写一个向导程序。在第一页上,我想让用户在两个选项之间进行两次选择。因此我决定制作 Buttongroups。但是,尽管我将前两个单选按钮添加到第一个 Buttongroup,将另外两个添加到第二个,但这些按钮仍然是独占的(我只能在页面上选择一个按钮)。

这是我的代码:

    # Setup UI
layout = QtGui.QVBoxLayout()

gBBackupFromIntExt = QtGui.QGroupBox()
layout.addWidget(gBBackupFromIntExt)

bGBackupFromIntExt = QtGui.QButtonGroup()

self.rBBackupFromExt = QtGui.QRadioButton()
bGBackupFromIntExt.addButton (self.rBBackupFromExt)
layout.addWidget(self.rBBackupFromExt)

self.rBBackupFromInt = QtGui.QRadioButton()
bGBackupFromIntExt.addButton (self.rBBackupFromInt)
layout.addWidget(self.rBBackupFromInt)

gBBackupToIntExt = QtGui.QGroupBox()
layout.addWidget(gBBackupToIntExt)

bGBackupToIntExt = QtGui.QButtonGroup()

self.rBBackupToExt = QtGui.QRadioButton()
bGBackupToIntExt.addButton (self.rBBackupToExt)
layout.addWidget(self.rBBackupToExt)

self.rBBackupToInt = QtGui.QRadioButton()
bGBackupToIntExt.addButton (self.rBBackupToInt)
layout.addWidget(self.rBBackupToInt)

您知道我的错误在哪里以及我必须更改什么吗?

最佳答案

问题是 QButtonGroups 从来没有成为层次结构的一部分,所以它们没有效果。

顺便说一句:在发布代码时尝试添加必要的部分以使其可运行:

from PyQt4 import QtGui
import sys

class Test(QtGui.QWidget):
def __init__(self):
super().__init__()
layout = QtGui.QVBoxLayout(self)

gBBackupFromIntExt = QtGui.QGroupBox()
layout.addWidget(gBBackupFromIntExt)

bGBackupFromIntExt = QtGui.QButtonGroup(self)

self.rBBackupFromExt = QtGui.QRadioButton()
bGBackupFromIntExt.addButton(self.rBBackupFromExt)
layout.addWidget(self.rBBackupFromExt)

self.rBBackupFromInt = QtGui.QRadioButton()
bGBackupFromIntExt.addButton(self.rBBackupFromInt)
layout.addWidget(self.rBBackupFromInt)

gBBackupToIntExt = QtGui.QGroupBox()
layout.addWidget(gBBackupToIntExt)

bGBackupToIntExt = QtGui.QButtonGroup(self)

self.rBBackupToExt = QtGui.QRadioButton()
bGBackupToIntExt.addButton (self.rBBackupToExt)
layout.addWidget(self.rBBackupToExt)

self.rBBackupToInt = QtGui.QRadioButton()
bGBackupToIntExt.addButton (self.rBBackupToInt)
layout.addWidget(self.rBBackupToInt)

a = QtGui.QApplication(sys.argv)
t = Test()
t.show()
a.exec()

这应该可以解决问题。

关于python - 一个窗口中的多个 QButtonGroups,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13731809/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com