本文整理匯總了Python中qtpy.QtWidgets.QComboBox方法的典型用法代碼示例。如果您正苦於以下問題:Python QtWidgets.QComboBox方法的具體用法?Python QtWidgets.QComboBox怎麽用?Python QtWidgets.QComboBox使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QComboBox方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_model_item
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def test_model_item():
"""
This is a regression test for an issue that caused the call to item(0)
below to trigger segmentation faults in PySide. The issue is
non-deterministic when running the call once, so we include a loop to make
sure that we trigger the fault.
"""
app = get_qapp()
combo = QtWidgets.QComboBox()
label_data = [('a', None)]
for iter in range(10000):
combo.clear()
for i, (label, data) in enumerate(label_data):
combo.addItem(label, userData=data)
model = combo.model()
model.item(0)
示例2: __init__
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def __init__(self, layout: QtWidgets.QLayout, text: str, values: Sequence):
""" A combo box widget with a label
Args:
layout: the layout to which to add the widget
text: the label text
values: the possible values of the combo box
"""
QtWidgets.QWidget.__init__(self)
layout.addWidget(self)
self.layout = QtWidgets.QHBoxLayout(self)
self.label = QtWidgets.QLabel(text)
self.layout.addWidget(self.label)
self.layout.setContentsMargins(0, 0, 0, 0)
self.values = values
self.input1 = QtWidgets.QComboBox()
self.input1.addItems(values)
self.layout.addWidget(self.input1)
self.input1.currentIndexChanged.connect(self.valueChangeEvent)
self.layout.addWidget(self.input1)
示例3: __init__
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def __init__(self, number, name, options, decimals=3):
super(ListComboBox, self).__init__()
self.setToolTip("First order filter frequencies \n"
"negative values are for high-pass \n"
"positive for low pass")
self.lay = QtWidgets.QHBoxLayout()
self.lay.setContentsMargins(0, 0, 0, 0)
self.combos = []
self.options = options
self.decimals = decimals
for i in range(number):
combo = QtWidgets.QComboBox()
self.combos.append(combo)
combo.addItems(self.options)
combo.currentIndexChanged.connect(self.value_changed)
self.lay.addWidget(combo)
self.setLayout(self.lay)
示例4: enabled_qcombobox_subclass
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def enabled_qcombobox_subclass(tmpdir):
"""
Context manager that sets up a temporary module with a QComboBox subclass
and then removes it once we are done.
"""
with open(tmpdir.join('qcombobox_subclass.py').strpath, 'w') as f:
f.write(QCOMBOBOX_SUBCLASS)
sys.path.insert(0, tmpdir.strpath)
yield
sys.path.pop(0)
示例5: test_load_ui
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def test_load_ui():
"""
Make sure that the patched loadUi function behaves as expected with a
simple .ui file.
"""
app = get_qapp()
ui = loadUi(os.path.join(os.path.dirname(__file__), 'test.ui'))
assert isinstance(ui.pushButton, QtWidgets.QPushButton)
assert isinstance(ui.comboBox, QComboBox)
示例6: set_custom_color
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def set_custom_color(color_box: QComboBox, color_text: str):
color_index = color_box.findText(color_text)
if color_index > -1:
color_box.setCurrentIndex(color_index)
else:
color_box.addItem(color_icon(color_text), color_text)
color_box.setCurrentIndex(color_box.count() - 1)
示例7: add_custom_color
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def add_custom_color(color_box: QComboBox, color: QColor):
rgb_str = f"({color.red()}, {color.green()}, {color.blue()})"
color_box.addItem(color_icon(rgb_str), rgb_str)
color_box.setCurrentIndex(color_box.count() - 1)
示例8: _make_widget
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def _make_widget(self):
self.widget = QtWidgets.QComboBox()
self.widget.addItems(self.options)
self.widget.currentIndexChanged.connect(self.write_widget_value_to_attribute)
示例9: test_patched_qcombobox
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def test_patched_qcombobox():
"""
In PySide, using Python objects as userData in QComboBox causes
Segmentation faults under certain conditions. Even in cases where it
doesn't, findData does not work correctly. Likewise, findData also
does not work correctly with Python objects when using PyQt4. On the
other hand, PyQt5 deals with this case correctly. We therefore patch
QComboBox when using PyQt4 and PySide to avoid issues.
"""
app = get_qapp()
data1 = Data()
data2 = Data()
data3 = Data()
data4 = Data()
data5 = Data()
data6 = Data()
icon1 = QtGui.QIcon()
icon2 = QtGui.QIcon()
widget = QtWidgets.QComboBox()
widget.addItem('a', data1)
widget.insertItem(0, 'b', data2)
widget.addItem('c', data1)
widget.setItemData(2, data3)
widget.addItem(icon1, 'd', data4)
widget.insertItem(3, icon2, 'e', data5)
widget.addItem(icon1, 'f')
widget.insertItem(5, icon2, 'g')
widget.show()
assert widget.findData(data1) == 1
assert widget.findData(data2) == 0
assert widget.findData(data3) == 2
assert widget.findData(data4) == 4
assert widget.findData(data5) == 3
assert widget.findData(data6) == -1
assert widget.itemData(0) == data2
assert widget.itemData(1) == data1
assert widget.itemData(2) == data3
assert widget.itemData(3) == data5
assert widget.itemData(4) == data4
assert widget.itemData(5) is None
assert widget.itemData(6) is None
assert widget.itemText(0) == 'b'
assert widget.itemText(1) == 'a'
assert widget.itemText(2) == 'c'
assert widget.itemText(3) == 'e'
assert widget.itemText(4) == 'd'
assert widget.itemText(5) == 'g'
assert widget.itemText(6) == 'f'
示例10: __init__
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def __init__(self, layer):
super().__init__(layer)
self.events.add(
colormap=Event,
contrast_limits=Event,
contrast_limits_range=Event,
gamma=Event,
)
comboBox = QComboBox(self)
comboBox.setObjectName("colormapComboBox")
comboBox.activated[str].connect(self.events.colormap)
self.colormapComboBox = comboBox
# Create contrast_limits slider
self.contrastLimitsSlider = QHRangeSlider(parent=self)
self.contrastLimitsSlider.mousePressEvent = self._clim_mousepress
self.contrastLimitsSlider.valuesChanged.connect(
self.events.contrast_limits
)
self.contrastLimitsSlider.rangeChanged.connect(
self.events.contrast_limits_range
)
# gamma slider
sld = QSlider(Qt.Horizontal, parent=self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setMinimum(2)
sld.setMaximum(200)
sld.setSingleStep(2)
sld.setValue(100)
sld.valueChanged.connect(lambda value: self.events.gamma(value / 100))
self.gammaSlider = sld
self.colorbarLabel = QLabel(parent=self)
self.colorbarLabel.setObjectName('colorbar')
self.colorbarLabel.setToolTip('Colorbar')
# Once EVH refactor is done, these can be moved to an initialization
# outside of this object
self._on_gamma_change(self.layer.gamma)
self._set_colormaps(self.layer.colormaps)
self._on_colormap_change(self.layer.colormap[0])
self._on_contrast_limits_range_change(self.layer.contrast_limits_range)
self._on_contrast_limits_change(self.layer.contrast_limits)
示例11: __init__
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QComboBox [as 別名]
def __init__(self, layer):
super().__init__()
self.events = EmitterGroup(
source=self,
auto_connect=False,
blending=Event,
opacity=Event,
status=Event,
)
# When the EVH refactor #1376 is done we might not even need the layer
# attribute anymore as all data updates will be through the handler.
# At that point we could remove the attribute and do the registering
# and connecting outside this class and never even need to pass the
# layer to this class.
self.layer = layer
self.layer.event_handler.register_listener(self)
self.events.connect(self.layer.event_handler.on_change)
self.setObjectName('layer')
self.setMouseTracking(True)
self.grid_layout = QGridLayout(self)
self.grid_layout.setContentsMargins(0, 0, 0, 0)
self.grid_layout.setSpacing(2)
self.grid_layout.setColumnMinimumWidth(0, 86)
self.grid_layout.setColumnStretch(1, 1)
self.setLayout(self.grid_layout)
sld = QSlider(Qt.Horizontal, parent=self)
sld.setFocusPolicy(Qt.NoFocus)
sld.setMinimum(0)
sld.setMaximum(100)
sld.setSingleStep(1)
sld.valueChanged.connect(lambda v: self.events.opacity(v / 100))
self.opacitySlider = sld
blend_comboBox = QComboBox(self)
blend_comboBox.addItems(Blending.keys())
blend_comboBox.activated[str].connect(self.events.blending)
self.blendComboBox = blend_comboBox
# Once EVH refactor is done, these can be moved to an initialization
# outside of this object
self._on_opacity_change(self.layer.opacity)
self._on_blending_change(self.layer.blending)