本文整理汇总了Python中PyQt5.QtWidgets.QButtonGroup.addButton方法的典型用法代码示例。如果您正苦于以下问题:Python QButtonGroup.addButton方法的具体用法?Python QButtonGroup.addButton怎么用?Python QButtonGroup.addButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QButtonGroup
的用法示例。
在下文中一共展示了QButtonGroup.addButton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ui_Widget
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class Ui_Widget(object):
""" Klasa definiująca GUI """
def setupUi(self, Widget):
# widgety rysujące kształty, instancje klasy Ksztalt
self.ksztalt1 = Ksztalt(self, Ksztalty.Polygon)
self.ksztalt2 = Ksztalt(self, Ksztalty.Ellipse)
self.ksztaltAktywny = self.ksztalt1
# przyciski CheckBox ###
uklad = QVBoxLayout() # układ pionowy
self.grupaChk = QButtonGroup()
for i, v in enumerate(('Kwadrat', 'Koło', 'Trójkąt', 'Linia')):
self.chk = QCheckBox(v)
self.grupaChk.addButton(self.chk, i)
uklad.addWidget(self.chk)
self.grupaChk.buttons()[self.ksztaltAktywny.ksztalt].setChecked(True)
# CheckBox do wyboru aktywnego kształtu
self.ksztaltChk = QCheckBox('<=')
self.ksztaltChk.setChecked(True)
uklad.addWidget(self.ksztaltChk)
# układ poziomy dla kształtów oraz przycisków CheckBox
ukladH1 = QHBoxLayout()
ukladH1.addWidget(self.ksztalt1)
ukladH1.addLayout(uklad)
ukladH1.addWidget(self.ksztalt2)
# koniec CheckBox ###
self.setLayout(ukladH1) # przypisanie układu do okna głównego
self.setWindowTitle('Widżety')
示例2: intervalButtons
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def intervalButtons(self):
widget = QGroupBox('Interval')
group = QButtonGroup(widget)
layout = QHBoxLayout()
widget.setLayout(layout)
def setInterval():
self.interval = group.checkedId()
interval = self.INTERVALS[self.interval][0]
self.updateTitle()
if interval:
self.progress.show()
self.progress.setMaximum(interval)
value = self.timer.seconds()
if value < interval:
self.progress.resume()
else:
self.progress.stop()
self.progress.setValue(min(interval, value))
else:
self.progress.hide()
for i, interval in enumerate(self.INTERVALS):
button = QPushButton(interval[1])
button.setCheckable(True)
button.clicked.connect(setInterval)
group.addButton(button, i)
layout.addWidget(button, 1 if i > 0 else 0)
return widget
示例3: LabelButtonGroup
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class LabelButtonGroup(QWidget):
def __init__(self, label = '', buttons = {'UJ object reference value': 'Name to show'}):
super(LabelButtonGroup, self).__init__()
self.label = QLabel()
self.label.setText(label)
self.button_group = QButtonGroup()
self.buttons = {}
self.layout = QHBoxLayout()
self.layout.setContentsMargins(0,0,0,0)
self.layout.addWidget(self.label)
for button_key in buttons.keys():
self.buttons[button_key] = QRadioButton(buttons[button_key])
self.button_group.addButton(self.buttons[button_key])
self.layout.addWidget(self.buttons[button_key])
def show(self):
for button in self.buttons.values():
button.show()
self.label.show()
def hide(self):
for button in self.buttons.values():
button.hide()
self.label.hide()
def set_text(self, key):
if key != '':
self.buttons[key].setChecked(1)
def text(self):
return self.button_group.checkedButton().text()
def checked(self):
return self.button_group.checkedButton()
示例4: add_radiobuttons
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def add_radiobuttons(self, tab=False):
from PyQt5.QtWidgets import QRadioButton, QButtonGroup, QVBoxLayout
scrollLayout = QVBoxLayout()
buttonGroup = QButtonGroup()
buttongroup_results = {}
i = 1
if tab:
name = "tab"
i = 2
elif arguments.radiolist:
name = "radiolist"
elif arguments.menu:
name = "menu"
arglen = len(arguments.__dict__[name])
while i < arglen:
if arguments.radiolist:
radiobutton = QRadioButton(arguments.__dict__[name][i+1])
buttongroup_results[radiobutton] = arguments.__dict__[name][i]
if arguments.__dict__[name][i+2].lower() in ["true", "on"]:
radiobutton.setChecked(True)
i += 3
else:
radiobutton = QRadioButton(arguments.__dict__[name][i+1])
buttongroup_results[radiobutton] = arguments.__dict__[name][i]
if i == 1:
radiobutton.setChecked(True)
i += 2
scrollLayout.addWidget(radiobutton)
buttonGroup.addButton(radiobutton)
return scrollLayout, buttonGroup, buttongroup_results
示例5: GSideToolbar
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class GSideToolbar(QWidget):
selectionChanged = pyqtSignal(str)
def __init__(self, buttons):
super().__init__()
self.selectedId = None
self.mainLayout = QVBoxLayout(self)
self.buttonGroup = QButtonGroup()
self.buttons = {}
for button in buttons:
b = QPushButton(button.name)
self.buttonGroup.addButton(b)
self.buttonGroup.setId(b, button.id)
self.buttons[button.id] = b
self.mainLayout.addWidget(b)
self.buttonGroup.buttonClicked.connect(self.buttonClicked)
self.mainLayout.addStretch()
def buttonState(self, state):
pass
def buttonClicked(self, button : QPushButton):
buttonId = self.buttonGroup.id(button)
buttonName = self.buttons[buttonId].text()
self.selectionChanged.emit(buttonName)
@staticmethod
def createButton(text, icon):
pass
示例6: DyStockSelectAddColumnsDlg
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class DyStockSelectAddColumnsDlg(QDialog):
def __init__(self, data, title, parent=None):
super().__init__(parent)
self._data = data
self._initUi(title)
def _initUi(self, title):
self.setWindowTitle('添加{0}列'.format(title))
# 控件
increaseColumnsLable = QLabel('基准日期几日{0}'.format(title))
self._increaseColumnsLineEdit = QLineEdit(','.join(self._data['days']) if self._data else '2,3,4,5,10' )
# 前 & 后
forwardRadioButton = QRadioButton('向前')
backwardRadioButton = QRadioButton('向后'); backwardRadioButton.setChecked(True)
# 添加到QButtonGroup
self._wardButtonGroup = QButtonGroup()
self._wardButtonGroup.addButton(forwardRadioButton, 1);
self._wardButtonGroup.addButton(backwardRadioButton, 2)
cancelPushButton = QPushButton('Cancel')
okPushButton = QPushButton('OK')
cancelPushButton.clicked.connect(self._cancel)
okPushButton.clicked.connect(self._ok)
# 布局
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(increaseColumnsLable, 0, 0, 1, 2)
grid.addWidget(self._increaseColumnsLineEdit, 1, 0, 1, 2)
grid.addWidget(forwardRadioButton, 2, 0)
grid.addWidget(backwardRadioButton, 2, 1)
grid.addWidget(okPushButton, 3, 1)
grid.addWidget(cancelPushButton, 3, 0)
self.setLayout(grid)
self.setMinimumWidth(QApplication.desktop().size().width()//5)
def _ok(self):
checkedButton = self._wardButtonGroup.checkedButton()
text = checkedButton.text()
self._data['backward'] = True if text == '向后' else False
self._data['days'] = [int(x) for x in self._increaseColumnsLineEdit.text().split(',')]
self.accept()
def _cancel(self):
self.reject()
示例7: createGroupBox
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def createGroupBox(self, layout):
group1 = QGroupBox(self)
group1.setTitle(self.tr("Clicking Behavior"))
group1.setMinimumHeight(150)
group1.setMaximumWidth(300)
layout.addWidget(group1)
vlayout1 = QVBoxLayout(group1)
buttonGroup = QButtonGroup(group1)
self.radiobutton1 = QRadioButton(group1)
self.radiobutton1.setText(self.tr("Single-click to open files and folders."))
self.radiobutton1.setChecked(True)
vlayout1.addWidget(self.radiobutton1)
self.radiobutton2 = QRadioButton(group1)
self.radiobutton2.setText(self.tr("Double-click to open files and folders."))
self.radiobutton2.setChecked(False)
vlayout1.addWidget(self.radiobutton2)
buttonGroup.addButton(self.radiobutton1)
buttonGroup.addButton(self.radiobutton2)
buttonGroup.buttonClicked.connect(self.folderClick)
group2 = QGroupBox(self)
group2.setTitle(self.tr("Button Order"))
group2.setMinimumHeight(150)
group2.setMaximumWidth(300)
layout.addWidget(group2)
vlayout2 = QVBoxLayout(group2)
buttonGroup2 = QButtonGroup(group2)
self.radiobutton3 = QRadioButton(group2)
self.radiobutton3.setText(self.tr("Right hand."))
self.radiobutton3.setChecked(True)
vlayout2.addWidget(self.radiobutton3)
self.radiobutton4 = QRadioButton(group2)
self.radiobutton4.setText(self.tr("Left hand."))
vlayout2.addWidget(self.radiobutton4)
buttonGroup2.addButton(self.radiobutton3)
buttonGroup2.addButton(self.radiobutton4)
buttonGroup2.buttonClicked.connect(self.mouseButton)
self.checkbox = QCheckBox(group2)
self.checkbox.setText(self.tr("Reverse scrolling."))
self.checkbox.clicked.connect(self.reverseScroll)
vlayout2.addWidget(self.checkbox)
示例8: create_menu_buttons
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def create_menu_buttons(self):
# Center on Player Button
button_center_player = QPushButton(
QIcon('maps/graphics/map_menu_center_player.png'),
''
)
button_center_player.setCheckable(True) # Make toggle button
button_center_player.setToolTip('Center on Player')
button_center_player.setObjectName('button_center_player')
# Center on Last Point Button
button_center_point = QPushButton(
QIcon('maps/graphics/map_menu_center_map.png'),
''
)
button_center_point.setCheckable(True) # Make toggle button
button_center_point.setToolTip('Center Normally')
button_center_point.setObjectName('button_center_point')
# Create Button Group for Exclusive Toggling
toggle_group = QButtonGroup(self)
toggle_group.addButton(button_center_player, 1)
toggle_group.addButton(button_center_point, 2)
toggle_group.buttonClicked.connect(self.center_button_toggled)
self.menu.addWidget(button_center_player)
self.menu.addWidget(button_center_point)
# Apply settings for current toggle
if self.settings.get_value('maps', 'center_on') == 'point':
button_center_point.setChecked(True)
else:
button_center_player.setChecked(True)
# Fit to Window Button
button_fit_window = QPushButton(
QIcon('maps/graphics/map_menu_fit_window.png'),
''
)
button_fit_window.setToolTip('Fit Map to Window')
button_fit_window.clicked.connect(self.fit_to_window)
self.menu.addWidget(button_fit_window, 0, Qt.AlignLeft)
# Maps Combo Box
self.combo_load_map = QComboBox(self)
# Need to setView otherwise CSS doesn't work
self.combo_load_map.setView(QListView())
self.combo_load_map.setToolTip('Manually Load Selected Map')
for map_name in sorted(self.map_pairs.keys(), key=str.lower):
self.combo_load_map.addItem(map_name)
self.combo_load_map.currentIndexChanged.connect(
self.load_map_from_combo
)
self.menu.addWidget(self.combo_load_map, 0, Qt.AlignLeft)
示例9: initUI
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def initUI(self):
# create menus
menu.GuiMenu()
menu.WidgetMenu()
menu.SettingsMenu()
menu.LoggingMenu()
# main layout
mainVLayout = QVBoxLayout()
elementHLayouts = []
# top element: toolbar, status
t = QLabel("Toolbar")
s = QLabel("Status")
toolbarStatusHLayout = QHBoxLayout()
toolbarStatusHLayout.addWidget(t)
toolbarStatusHLayout.addWidget(s)
elementHLayouts.append(toolbarStatusHLayout)
# mid element: menu buttons
menubuttonsHLayout = QHBoxLayout()
stackedButtonsWidget = QStackedWidget()
buttonGroup = QButtonGroup(self)
buttonGroup.setExclusive(True)
for m in menu.Menu.menus:
btn = QPushButton(m.name)
btn.setCheckable(True)
btn.pressed.connect(lambda m=m: stackedButtonsWidget.setCurrentWidget(m))
menubuttonsHLayout.addWidget(btn)
buttonGroup.addButton(btn)
stackedButtonsWidget.addWidget(m)
elementHLayouts.append(menubuttonsHLayout)
# bot element: menu specific widgets
menuwidgetsHLayout = QHBoxLayout()
menuwidgetsHLayout.addWidget(stackedButtonsWidget)
elementHLayouts.append(menuwidgetsHLayout)
# click first button for defined initial state
if len(buttonGroup.buttons()) > 0:
buttonGroup.buttons()[0].click()
for l in elementHLayouts:
mainVLayout.addLayout(l)
self.setLayout(mainVLayout)
示例10: DyStockTableSelectDlg
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class DyStockTableSelectDlg(QDialog):
def __init__(self, data, dlgName):
super().__init__()
self._data = data
self._initUi(dlgName)
def _initUi(self, dlgName):
self.setWindowTitle(dlgName)
allRadioButton = QRadioButton('所有'); allRadioButton.setChecked(True)
highlightRadioButton = QRadioButton('高亮')
# 添加到QButtonGroup
self._buttonGroup = QButtonGroup()
self._buttonGroup.addButton(allRadioButton, 1);
self._buttonGroup.addButton(highlightRadioButton, 2)
cancelPushButton = QPushButton('Cancel')
okPushButton = QPushButton('OK')
cancelPushButton.clicked.connect(self._cancel)
okPushButton.clicked.connect(self._ok)
# 布局
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(allRadioButton, 1, 0)
grid.addWidget(highlightRadioButton, 1, 1)
grid.addWidget(okPushButton, 2, 1)
grid.addWidget(cancelPushButton, 2, 0)
self.setLayout(grid)
self.setMinimumWidth(QApplication.desktop().size().width()//5)
def _ok(self):
checkedButton = self._buttonGroup.checkedButton()
text = checkedButton.text()
self._data['all'] = True if text == '所有' else False
self.accept()
def _cancel(self):
self.reject()
示例11: InputRadioGroup
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class InputRadioGroup(QWidget):
"""Create an horizontal radio group"""
def __init__(self, parent=None, option_list=None, default_select=0):
super().__init__(parent=parent)
layout = QHBoxLayout(self)
self.group = QButtonGroup()
for idx, op in enumerate(option_list):
self.op = QRadioButton(_(op))
if idx == default_select:
self.op.setChecked(True)
layout.addWidget(self.op)
self.group.addButton(self.op)
self.setLayout(layout)
@pyqtProperty(str)
def currentItemData(self):
return str(abs(int(self.group.checkedId())) - 1)
示例12: contextButtons
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def contextButtons(self):
widget = QGroupBox('Context')
group = QButtonGroup(widget)
layout = QHBoxLayout()
widget.setLayout(layout)
def setContext():
self.context = self.CONTEXTS[group.checkedId()]
self.updateTitle()
for i, context in enumerate(self.CONTEXTS):
button = QPushButton(context.title() if context else 'None')
button.setCheckable(True)
button.clicked.connect(setContext)
group.addButton(button, i)
layout.addWidget(button, 1 if i > 0 else 0)
return widget
示例13: RadioGroup
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class RadioGroup(object):
def __init__(self,
value_text_tuples: Iterable[Tuple[str, Any]],
default: Any = None) -> None:
# There's no reason for the caller to care about the internal IDs
# we use. So let's make them up here as positive integers.
self.default_value = default
if not value_text_tuples:
raise ValueError("No values passed to RadioGroup")
if contains_duplicates([x[0] for x in value_text_tuples]):
raise ValueError("Duplicate values passed to RadioGroup")
possible_values = [x[0] for x in value_text_tuples]
if self.default_value not in possible_values:
self.default_value = possible_values[0]
self.bg = QButtonGroup() # exclusive by default
self.buttons = []
self.map_id_to_value = {}
self.map_value_to_button = {}
for i, (value, text) in enumerate(value_text_tuples):
id_ = i + 1 # start with 1
button = QRadioButton(text)
self.bg.addButton(button, id_)
self.buttons.append(button)
self.map_id_to_value[id_] = value
self.map_value_to_button[value] = button
def get_value(self) -> Any:
buttongroup_id = self.bg.checkedId()
if buttongroup_id == NOTHING_SELECTED:
return None
return self.map_id_to_value[buttongroup_id]
def set_value(self, value: Any) -> None:
if value not in self.map_value_to_button:
value = self.default_value
button = self.map_value_to_button[value]
button.setChecked(True)
def add_buttons_to_layout(self, layout: QLayout) -> None:
for button in self.buttons:
layout.addWidget(button)
示例14: CopyConfigDialog
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
class CopyConfigDialog(ConfigDialog):
def __init__(self, mode=None):
super().__init__()
self.__initUI()
self.setSelectedCopyMode(mode)
def __initUI(self):
super().initUI()
self.setWindowTitle("画像コピー設定")
self.layout = QGridLayout()
self.radioGroup = QButtonGroup()
self.radioButton1 = QRadioButton("左右反転")
self.radioButton2 = QRadioButton("上下反転")
self.radioButton3 = QRadioButton("左右上下反転")
self.radioGroup.addButton(self.radioButton1)
self.radioGroup.addButton(self.radioButton2)
self.radioGroup.addButton(self.radioButton3)
self.layout.addWidget(self.radioButton1, 0, 0)
self.layout.addWidget(self.radioButton2, 1, 0)
self.layout.addWidget(self.radioButton3, 2, 0)
self.layout.addWidget(self.btnBox, 3, 1)
self.setLayout(self.layout)
"""コピー設定モードUI反映処理"""
def setSelectedCopyMode(self, mode):
if mode == Constant.LR_REVERSAL_MODE or mode is None:
self.radioButton1.setChecked(True)
elif mode == Constant.TB_REVERSAL_MODE:
self.radioButton2.setChecked(True)
else:
self.radioButton3.setChecked(True)
"""コピー設定モード取得処理"""
def getSelectedCopyMode(self):
if self.radioButton1.isChecked():
return Constant.LR_REVERSAL_MODE
elif self.radioButton2.isChecked():
return Constant.TB_REVERSAL_MODE
else:
return Constant.LRTB_REVERSAL_MODE
示例15: __init__
# 需要导入模块: from PyQt5.QtWidgets import QButtonGroup [as 别名]
# 或者: from PyQt5.QtWidgets.QButtonGroup import addButton [as 别名]
def __init__(self, result):
QDialog.__init__(self)
self.layout = QVBoxLayout(self)
self.result = result
observation_window = result.observation_window
group = QButtonGroup(self)
use_simu_duration = QRadioButton("Use entire simulation.")
use_simu_duration.setChecked(
observation_window[0] == 0
and observation_window[1] == result.model.duration)
group.addButton(use_simu_duration)
self.layout.addWidget(use_simu_duration)
use_custom = QRadioButton("Use a custom observation window:")
use_custom.setChecked(not use_simu_duration.isChecked())
group.addButton(use_custom)
self.layout.addWidget(use_custom)
self._slider = QxtSpanSliderWidget(
0, result.model.now() // result.model.cycles_per_ms, self)
self._slider.setSpan(
observation_window[0] // result.model.cycles_per_ms,
observation_window[1] // result.model.cycles_per_ms)
self._slider.setEnabled(use_custom.isChecked())
group.buttonClicked.connect(
lambda x: self._slider.setEnabled(x == use_custom))
self.layout.addWidget(self._slider)
buttons = QWidget(self)
buttons_layout = QHBoxLayout()
buttons.setLayout(buttons_layout)
buttons_layout.addStretch()
ok_button = QPushButton("Ok")
cancel_button = QPushButton("Cancel")
ok_button.clicked.connect(self.accept)
cancel_button.clicked.connect(self.reject)
buttons_layout.addWidget(ok_button)
buttons_layout.addWidget(cancel_button)
self.layout.addWidget(buttons)