def __init__(self, choices, title = "select one from choices", parent = None):
super(ChoiceDialog, self).__init__(parent)
layout = QVBoxLayout(self)
self.choiceButtonGroup=QButtonGroup(parent) # it is not a visible UI
self.choiceButtonGroup.setExclusive(True)
if choices and len(choices)>=1:
self.choices = choices
for id, choice in enumerate(self.choices):
rb = QRadioButton(choice)
self.choiceButtonGroup.addButton(rb)
self.choiceButtonGroup.setId(rb, id) # negative id if not specified
layout.addWidget(rb)
self.choiceButtonGroup.buttonClicked.connect(self.choiceChanged)
# OK and Cancel buttons
buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
Qt.Horizontal, self)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
layout.addWidget(buttons)
self.setLayout(layout)
self.setWindowTitle(title)
评论列表
文章目录