本文整理汇总了Python中qtpy.QtWidgets.QComboBox类的典型用法代码示例。如果您正苦于以下问题:Python QComboBox类的具体用法?Python QComboBox怎么用?Python QComboBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QComboBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, editor):
Panel.__init__(self, editor)
self._editor = editor
self._editor.sig_cursor_position_changed.connect(
self._handle_cursor_position_change_event
)
# The layout
hbox = QHBoxLayout()
self.class_cb = QComboBox()
self.method_cb = QComboBox()
hbox.addWidget(self.class_cb)
hbox.addWidget(self.method_cb)
hbox.setSpacing(0)
hbox.setContentsMargins(0, 0, 0, 0)
self.setLayout(hbox)
# Internal data
self.folds = None
self.parents = None
self.classes = None
self.funcs = None
# Initial data for the dropdowns.
self.class_cb.addItem("<None>", 0)
self.method_cb.addItem("<None>", 0)
# Attach some events.
self.class_cb.activated.connect(self.combobox_activated)
self.method_cb.activated.connect(self.combobox_activated)
示例2: populate_unit_layout
def populate_unit_layout(self, unit_layout, gui=None):
"""
Populate horizontal layout (living on conversion gui)
with appropriate widgets.
Layouts:
[QComboBox]
:param unit_layout: (QHBoxLayout) Horizontal layout
:param gui: conversion gui
:return: updated unit_layout
"""
unit_str = self._unit.to_string()
options = self._unit.find_equivalent_units(include_prefix_units=True)
options = [i.to_string() for i in options]
options.sort(key=lambda x: x.upper())
if unit_str not in options:
options.append(unit_str)
index = options.index(unit_str)
combo = QComboBox()
# combo.setFixedWidth(200)
combo.addItems(options)
combo.setCurrentIndex(index)
combo.currentIndexChanged.connect(self._update_message)
self.options_combo = combo
unit_layout.addWidget(combo)
self._update_message()
return unit_layout
示例3: buttonwidget
class buttonwidget(QWidget):
def __init__(self):
# how connect
super(buttonwidget, self).__init__()
self.grid = QGridLayout()
self.btnConnect = QPushButton("Connect")
self.grid.addWidget(self.btnConnect, 0, 0, 1, 5)
self.btnLock = QPushButton("Lock Cassette")
self.grid.addWidget(self.btnLock, 1, 0, 1, 5)
self.btnPurge = QPushButton("Purge")
self.grid.addWidget(self.btnPurge, 2, 0, 1, 2)
self.cbxPurgeType = QComboBox()
self.cbxPurgeType.addItems(["Normal", "Extended", "Add Conditioner", "Custom"])
self.grid.addWidget(self.cbxPurgeType, 2, 2, 1, 2)
self.txtNumPurge = QLineEdit()
self.grid.addWidget(self.txtNumPurge, 2, 4, 1, 1)
self.btnRecover = QPushButton("Recover")
self.grid.addWidget(self.btnRecover, 3, 0, 1, 5)
self.btnHelp = QPushButton("Help")
self.grid.addWidget(self.btnHelp, 4, 0, 1, 5)
self.setLayout(self.grid)
def updateButtonText(self):
print('updating text')
def EnableDisableButtons(self):
print('enabeling,disabeling buttons')
示例4: FormComboWidget
class FormComboWidget(QWidget):
update_buttons = Signal()
def __init__(self, datalist, comment="", parent=None):
QWidget.__init__(self, parent)
layout = QVBoxLayout()
self.setLayout(layout)
self.combobox = QComboBox()
layout.addWidget(self.combobox)
self.stackwidget = QStackedWidget(self)
layout.addWidget(self.stackwidget)
self.combobox.currentIndexChanged.connect(
self.stackwidget.setCurrentIndex)
self.widgetlist = []
for data, title, comment in datalist:
self.combobox.addItem(title)
widget = FormWidget(data, comment=comment, parent=self)
self.stackwidget.addWidget(widget)
self.widgetlist.append(widget)
def setup(self):
for widget in self.widgetlist:
widget.setup()
def get(self):
return [ widget.get() for widget in self.widgetlist]
示例5: _CompositionWidget
class _CompositionWidget(_ConditionWidget):
def _init_ui(self):
# Widgets
self._cb_unit = QComboBox()
self._cb_unit.addItems(list(_COMPOSITION_UNITS))
# Layouts
layout = _ConditionWidget._init_ui(self)
layout.addRow('<i>Unit</i>', self._cb_unit)
# Signals
self._cb_unit.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _ConditionWidget.parameter(self, parameter)
parameter.unit = self._cb_unit.currentText()
return parameter
def setParameter(self, condition):
_ConditionWidget.setParameter(self, condition)
self._cb_unit.setCurrentIndex(self._cb_unit.findText(condition.unit))
def setReadOnly(self, state):
_ConditionWidget.setReadOnly(self, state)
self._cb_unit.setEnabled(not state)
def isReadOnly(self):
return _ConditionWidget.isReadOnly(self) and \
not self._cb_unit.isEnabled()
示例6: _init_ui
def _init_ui(self):
self.slit_type_label = QLabel('Slit Type')
self.slit_type_combo = QComboBox()
self.slit_type_combo.currentIndexChanged.connect(self.update_info)
hbl1 = QHBoxLayout()
hbl1.addWidget(self.slit_type_label)
hbl1.addWidget(self.slit_type_combo)
self.slit_width_label = QLabel('Slit Width')
self.slit_width_input = QLineEdit()
self.slit_width_combo = QComboBox()
self.slit_width_units = QLabel('arcsec')
hbl2 = QHBoxLayout()
hbl2.addWidget(self.slit_width_label)
hbl2.addWidget(self.slit_width_input)
hbl2.addWidget(self.slit_width_combo)
hbl2.addWidget(self.slit_width_units)
self.slit_length_label = QLabel('Slit Length')
self.slit_length_input = QLineEdit()
self.slit_length_combo = QComboBox()
self.slit_length_units = QLabel('arcsec')
hbl3 = QHBoxLayout()
hbl3.addWidget(self.slit_length_label)
hbl3.addWidget(self.slit_length_input)
hbl3.addWidget(self.slit_length_combo)
hbl3.addWidget(self.slit_length_units)
self.okButton = QPushButton('Apply')
self.okButton.clicked.connect(self.apply)
self.okButton.setDefault(True)
self.cancelButton = QPushButton('Cancel')
self.cancelButton.clicked.connect(self.cancel)
hbl4 = QHBoxLayout()
hbl4.addWidget(self.cancelButton)
hbl4.addWidget(self.okButton)
vbl = QVBoxLayout()
vbl.addLayout(hbl1)
vbl.addLayout(hbl2)
vbl.addLayout(hbl3)
vbl.addLayout(hbl4)
self.setLayout(vbl)
self.vbl = vbl
self._load_selections()
self._populate_combo()
self.update_info(0)
self.show()
示例7: _AcquisitionRasterWidget
class _AcquisitionRasterWidget(_AcquisitionWidget):
def _init_ui(self):
# Widgets
self._cb_raster_mode = QComboBox()
self._cb_raster_mode.addItems([None] + list(_RASTER_MODES))
# Layouts
layout = _AcquisitionWidget._init_ui(self)
layout.addRow('Raster mode', self._cb_raster_mode)
# Singals
self._cb_raster_mode.currentIndexChanged.connect(self.edited)
return layout
def parameter(self, parameter=None):
parameter = _AcquisitionWidget.parameter(self, parameter)
parameter.raster_mode = self._cb_raster_mode.currentText()
return parameter
def setParameter(self, condition):
_AcquisitionWidget.setParameter(self, condition)
self._cb_raster_mode.setCurrentIndex(self._cb_raster_mode.findText(condition.raster_mode))
def setReadOnly(self, state):
_AcquisitionWidget.setReadOnly(self, state)
self._cb_raster_mode.setEnabled(not state)
def isReadOnly(self):
return _AcquisitionWidget.isReadOnly(self) and \
not self._cb_raster_mode.isEnabled()
示例8: create_combobox
def create_combobox(self, text, choices, option, default=NoDefault,
tip=None, restart=False):
"""choices: couples (name, key)"""
label = QLabel(text)
combobox = QComboBox()
if tip is not None:
combobox.setToolTip(tip)
for name, key in choices:
if not (name is None and key is None):
combobox.addItem(name, to_qvariant(key))
# Insert separators
count = 0
for index, item in enumerate(choices):
name, key = item
if name is None and key is None:
combobox.insertSeparator(index + count)
count += 1
self.comboboxes[combobox] = (option, default)
layout = QHBoxLayout()
layout.addWidget(label)
layout.addWidget(combobox)
layout.addStretch(1)
layout.setContentsMargins(0, 0, 0, 0)
widget = QWidget(self)
widget.label = label
widget.combobox = combobox
widget.setLayout(layout)
combobox.restart_required = restart
combobox.label_text = text
return widget
示例9: focusOutEvent
def focusOutEvent(self, event):
"""Handle focus out event restoring the last valid selected path."""
# Calling asynchronously the 'add_current_text' to avoid crash
# https://groups.google.com/group/spyderlib/browse_thread/thread/2257abf530e210bd
if not self.is_valid():
lineedit = self.lineEdit()
QTimer.singleShot(50, lambda: lineedit.setText(self.selected_text))
hide_status = getattr(self.lineEdit(), 'hide_status_icon', None)
if hide_status:
hide_status()
QComboBox.focusOutEvent(self, event)
示例10: DetectorSpectrometerWidget
class DetectorSpectrometerWidget(_DetectorWidget):
def __init__(self, parent=None):
_DetectorWidget.__init__(self, DetectorSpectrometer, parent)
def _init_ui(self):
# Widgets
self._txt_channel_count = NumericalAttributeLineEdit(self.CLASS.channel_count)
self._txt_channel_count.setFormat('{0:d}')
self._wdg_calibration = CalibrationWidget()
self._cb_collection_mode = QComboBox()
self._cb_collection_mode.addItems([None] + list(_COLLECTION_MODES))
# Layout
layout = _DetectorWidget._init_ui(self)
layout.insertRow(0, '<i>Channel count</i>', self._txt_channel_count)
layout.insertRow(1, '<i>Calibration</i>', self._wdg_calibration)
layout.addRow('Collection mode', self._cb_collection_mode)
# Signals
self._txt_channel_count.textEdited.connect(self.edited)
self._wdg_calibration.edited.connect(self.edited)
self._cb_collection_mode.currentIndexChanged.connect(self.edited)
return layout
def _create_parameter(self):
return self.CLASS(1, CalibrationConstant('Quantity', 'm', 0.0))
def parameter(self, parameter=None):
parameter = _DetectorWidget.parameter(self, parameter)
parameter.channel_count = self._txt_channel_count.text()
parameter.calibration = self._wdg_calibration.calibration()
parameter.collection_mode = self._cb_collection_mode.currentText()
return parameter
def setParameter(self, condition):
_DetectorWidget.setParameter(self, condition)
self._txt_channel_count.setText(condition.channel_count)
self._wdg_calibration.setCalibration(condition.calibration)
self._cb_collection_mode.setCurrentIndex(self._cb_collection_mode.findText(condition.collection_mode))
def setReadOnly(self, state):
_DetectorWidget.setReadOnly(self, state)
self._txt_channel_count.setReadOnly(state)
self._wdg_calibration.setReadOnly(state)
self._cb_collection_mode.setEnabled(not state)
def isReadOnly(self):
return _DetectorWidget.isReadOnly(self) and \
self._txt_channel_count.isReadOnly() and \
self._wdg_calibration.isReadOnly() and \
not self._cb_collection_mode.isEnabled()
def hasAcceptableInput(self):
return _DetectorWidget.hasAcceptableInput(self) and \
self._txt_channel_count.hasAcceptableInput() and \
self._wdg_calibration.hasAcceptableInput()
示例11: keyPressEvent
def keyPressEvent(self, event):
"""Qt Override.
Handle key press events.
"""
if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
if self.add_current_text_if_valid():
self.selected()
self.hide_completer()
elif event.key() == Qt.Key_Escape:
self.set_current_text(self.selected_text)
self.hide_completer()
else:
QComboBox.keyPressEvent(self, event)
示例12: NewGrainDialog
class NewGrainDialog(QDialog):
def __init__(self):
super(NewGrainDialog, self).__init__()
self.setup_ui()
def setup_ui(self):
self.setWindowTitle("Add New Grain")
self.setWindowIcon(QIcon(RESOURCE_PATH + "icons/nakka-finocyl.gif"))
self.resize(400, 400)
controls = QGridLayout()
gb_frame = QGroupBox(self.tr("Grain Design"))
gb_frame.setLayout(controls)
self.cb_grain_type = QComboBox()
# TODO: make grain types auto propagate combobox
self.cb_grain_type.addItems([self.tr("Cylindrical (BATES)")])
controls.addWidget(QLabel(self.tr("Core Shape")), 0, 0)
controls.addWidget(self.cb_grain_type, 0, 1)
self.cb_propellant_type = QComboBox()
self.cb_propellant_type.addItems(app_context.propellant_db.propellant_names())
controls.addWidget(QLabel(self.tr("Propellant Type")), 1, 0)
controls.addWidget(self.cb_propellant_type, 1, 1)
# ok and cancel buttons
btn_ok = QPushButton(self.tr("Apply"))
btn_ok.clicked.connect(self.confirm_grain)
btn_cancel = QPushButton(self.tr("Close"))
btn_cancel.clicked.connect(self.close)
lay_btns = QHBoxLayout()
lay_btns.addWidget(btn_ok)
lay_btns.addWidget(btn_cancel)
frame_btns = QFrame()
frame_btns.setLayout(lay_btns)
# master layout
master = QVBoxLayout()
master.addWidget(gb_frame)
master.addSpacing(10)
master.addWidget(frame_btns)
self.setLayout(master)
def confirm_grain(self):
# grain = OpenBurnGrain.from_widget_factory(...)
pass
示例13: _make_search_box
def _make_search_box(self):
"""
Make a algorithm search box.
:return: A QComboBox
"""
search_box = QComboBox(self)
search_box.setEditable(True)
search_box.completer().setCompletionMode(QCompleter.PopupCompletion)
search_box.setInsertPolicy(QComboBox.NoInsert)
search_box.editTextChanged.connect(self._on_search_box_selection_changed)
search_box.lineEdit().returnPressed.connect(self.execute_algorithm)
return search_box
示例14: __init__
def __init__(self, parent, order):
super(LayoutSaveDialog, self).__init__(parent)
# variables
self._parent = parent
# widgets
self.combo_box = QComboBox(self)
self.combo_box.addItems(order)
self.combo_box.setEditable(True)
self.combo_box.clearEditText()
self.button_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel,
Qt.Horizontal, self)
self.button_ok = self.button_box.button(QDialogButtonBox.Ok)
self.button_cancel = self.button_box.button(QDialogButtonBox.Cancel)
# widget setup
self.button_ok.setEnabled(False)
self.dialog_size = QSize(300, 100)
self.setWindowTitle('Save layout as')
self.setModal(True)
self.setMinimumSize(self.dialog_size)
self.setFixedSize(self.dialog_size)
# layouts
self.layout = QVBoxLayout()
self.layout.addWidget(self.combo_box)
self.layout.addWidget(self.button_box)
self.setLayout(self.layout)
# signals and slots
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.close)
self.combo_box.editTextChanged.connect(self.check_text)
示例15: _init_ui
def _init_ui(self):
# Widgets
self._cb_technology = QComboBox()
self._cb_technology.addItems([None] + list(_XEDS_TECHNOLOGIES))
self._txt_nominal_throughput = NumericalAttributeLineEdit(self.CLASS.nominal_throughput)
self._txt_time_constant = NumericalAttributeLineEdit(self.CLASS.time_constant)
self._txt_strobe_rate = NumericalAttributeLineEdit(self.CLASS.strobe_rate)
self._wdg_window = WindowWidget()
# Layout
form = DetectorSpectrometerWidget._init_ui(self)
form.addRow('Technology', self._cb_technology)
form.addRow('Nominal throughput', self._txt_nominal_throughput)
form.addRow('Time constant', self._txt_time_constant)
form.addRow('Strobe rate', self._txt_strobe_rate)
form.addRow('Window', self._wdg_window)
# Signals
self._cb_technology.currentIndexChanged.connect(self.edited)
self._txt_nominal_throughput.textEdited.connect(self.edited)
self._txt_time_constant.textEdited.connect(self.edited)
self._txt_strobe_rate.textEdited.connect(self.edited)
self._wdg_window.edited.connect(self.edited)
return form