當前位置: 首頁>>代碼示例>>Python>>正文


Python QtWidgets.QComboBox方法代碼示例

本文整理匯總了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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:18,代碼來源:test_patch_qcombobox.py

示例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) 
開發者ID:rgerum,項目名稱:pylustrator,代碼行數:25,代碼來源:QLinkableWidgets.py

示例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) 
開發者ID:lneuhaus,項目名稱:pyrpl,代碼行數:19,代碼來源:attribute_widgets.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:16,代碼來源:test_uic.py

示例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) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:11,代碼來源:test_uic.py

示例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) 
開發者ID:KmolYuan,項目名稱:Pyslvs-UI,代碼行數:9,代碼來源:utility.py

示例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) 
開發者ID:KmolYuan,項目名稱:Pyslvs-UI,代碼行數:6,代碼來源:utility.py

示例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) 
開發者ID:lneuhaus,項目名稱:pyrpl,代碼行數:6,代碼來源:attribute_widgets.py

示例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' 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:58,代碼來源:test_patch_qcombobox.py

示例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) 
開發者ID:napari,項目名稱:napari,代碼行數:48,代碼來源:qt_image_base_layer.py

示例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) 
開發者ID:napari,項目名稱:napari,代碼行數:49,代碼來源:qt_base_layer.py


注:本文中的qtpy.QtWidgets.QComboBox方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。