def __init__(self, options, title='Exclusive Options', selected_index=None, parent=None): super(ExclusiveOptionGroup, self).__init__() self.setTitle(title) self.setLayout(QVBoxLayout()) self._button_group = QButtonGroup() self._button_group.setExclusive(True) self._options = options if parent == None: parent = self for (button_id, option) in enumerate(self._options): radio_button = QRadioButton( option.get('title', 'option %d' % button_id)) radio_button.setEnabled(option.get('enabled', True)) radio_button.setChecked( option.get('selected', False) or button_id == selected_index) radio_button.setToolTip(option.get('tooltip', '')) self._button_group.addButton(radio_button, button_id) parent.layout().addWidget(radio_button) if 'description' in option: parent.layout().addWidget(QLabel(option['description']))
def __init__(self, options, title='Exclusive Options', selected_index=None): super(ExclusiveOptionGroup, self).__init__() self.setTitle(title) self.setLayout(QVBoxLayout()) self._button_group = QButtonGroup() self._button_group.setExclusive(True) self._options = options button_id = 0 for option in self._options: button_id += 1 radio_button = QRadioButton( option.get('title', 'option %d' % button_id)) radio_button.setEnabled(option.get('enabled', True)) radio_button.setChecked( option.get('selected', False) or (button_id - 1) == selected_index) radio_button.setToolTip(option.get('tooltip', '')) widget = QWidget() widget.setLayout(QVBoxLayout()) widget.layout().addWidget(radio_button) if 'description' in option: widget.layout().addWidget(QLabel(option['description'])) self._button_group.addButton(radio_button, button_id) self.layout().addWidget(widget)
def __init__(self, options, title='Exclusive Options', selected_index=None, parent=None): super(ExclusiveOptionGroup, self).__init__() self.setTitle(title) self.setLayout(QVBoxLayout()) self._button_group = QButtonGroup() self._button_group.setExclusive(True) self._options = options if parent == None: parent = self for (button_id, option) in enumerate(self._options): radio_button = QRadioButton(option.get('title', 'option %d' % button_id)) radio_button.setEnabled(option.get('enabled', True)) radio_button.setChecked(option.get('selected', False) or button_id == selected_index) radio_button.setToolTip(option.get('tooltip', '')) self._button_group.addButton(radio_button, button_id) parent.layout().addWidget(radio_button) if 'description' in option: parent.layout().addWidget(QLabel(option['description']))