Python qtpy.QtWidgets.QComboBox() Examples

The following are 27 code examples of qtpy.QtWidgets.QComboBox(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module qtpy.QtWidgets , or try the search function .
Example #1
Source File: test_patch_qcombobox.py    From vnpy_crypto with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: QLinkableWidgets.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: test_patch_qcombobox.py    From qtpy with MIT License 6 votes vote down vote up
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) 
Example #5
Source File: test_patch_qcombobox.py    From winpython with MIT License 6 votes vote down vote up
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) 
Example #6
Source File: test_patch_qcombobox.py    From P4VFX with MIT License 6 votes vote down vote up
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) 
Example #7
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def _make_widget(self):
        """
        Sets up the widget (here a QComboBox)

        :return:
        """
        self.widget = QtWidgets.QListWidget()
        self.widget.addItems(self.options)
        self.widget.currentItemChanged.connect(self.write_widget_value_to_attribute) 
Example #8
Source File: attribute_widgets.py    From pyrpl with GNU General Public License v3.0 5 votes vote down vote up
def _make_widget(self):
        self.widget = QtWidgets.QComboBox()
        self.widget.addItems(self.options)
        self.widget.currentIndexChanged.connect(self.write_widget_value_to_attribute) 
Example #9
Source File: test_uic.py    From qtpy with MIT License 5 votes vote down vote up
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) 
Example #10
Source File: test_uic.py    From qtpy with MIT License 5 votes vote down vote up
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) 
Example #11
Source File: utility.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #12
Source File: utility.py    From Pyslvs-UI with GNU Affero General Public License v3.0 5 votes vote down vote up
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) 
Example #13
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
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) 
Example #14
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
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) 
Example #15
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
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) 
Example #16
Source File: test_uic.py    From P4VFX with MIT License 5 votes vote down vote up
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) 
Example #17
Source File: test_uic.py    From winpython with MIT License 5 votes vote down vote up
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) 
Example #18
Source File: test_uic.py    From winpython with MIT License 5 votes vote down vote up
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) 
Example #19
Source File: test_uic.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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) 
Example #20
Source File: test_uic.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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) 
Example #21
Source File: test_patch_qcombobox.py    From P4VFX with MIT License 4 votes vote down vote up
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' 
Example #22
Source File: test_patch_qcombobox.py    From P4VFX with MIT License 4 votes vote down vote up
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' 
Example #23
Source File: test_patch_qcombobox.py    From qtpy with MIT License 4 votes vote down vote up
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' 
Example #24
Source File: test_patch_qcombobox.py    From winpython with MIT License 4 votes vote down vote up
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' 
Example #25
Source File: qt_base_layer.py    From napari with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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) 
Example #26
Source File: qt_image_base_layer.py    From napari with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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) 
Example #27
Source File: test_patch_qcombobox.py    From vnpy_crypto with MIT License 4 votes vote down vote up
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'