<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PySide: Connecting QComboBox indices with strings]]></title><description><![CDATA[<p dir="auto">I would like to connect the QComboBox indeces with specific strings (i.e. when I select "A", I want that it prints "A has been selected", and when I select "B", then "B has been selected").</p>
<p dir="auto">I am new to PySide and learning, so I am sure there exists a simple solution. Help is appreciated.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/from">@<bdi>from</bdi></a> PySide import QtGui</p>
<pre><code>class Widget(QtGui.QWidget):

    def __init__(self, parent=None):
        super().__init__(parent)

        v_global_layout = QtGui.QVBoxLayout()

        method_selection = QtGui.QComboBox()
        method_selection.addItem("A")
        method_selection.addItem("B")

        v_global_layout.addWidget(method_selection)
        self.setLayout(v_global_layout)

        def do_somethinh():
            print("A has been selected!!!")
        method_selection.activated.connect(do_somethinh)


if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)

    main_window = Widget()
    main_window.setGeometry(100, 100, 640, 480)
    main_window.show()

    sys.exit(app.exec_())
</code></pre>
<p dir="auto">@</p>
]]></description><link>https://forum.qt.io/topic/47427/pyside-connecting-qcombobox-indices-with-strings</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 20:41:58 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/47427.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Oct 2014 16:40:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PySide: Connecting QComboBox indices with strings on Sun, 26 Oct 2014 20:19:14 GMT]]></title><description><![CDATA[<p dir="auto">You're welcome !</p>
<p dir="auto">Yes, that's also a good solution</p>
<p dir="auto">Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)</p>
]]></description><link>https://forum.qt.io/post/249044</link><guid isPermaLink="true">https://forum.qt.io/post/249044</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 26 Oct 2014 20:19:14 GMT</pubDate></item><item><title><![CDATA[Reply to PySide: Connecting QComboBox indices with strings on Sat, 25 Oct 2014 23:02:53 GMT]]></title><description><![CDATA[<p dir="auto">Thsnk you!</p>
<p dir="auto">I also found another way to do it:</p>
<p dir="auto">@def do_somethinh(text):<br />
print(text, "has been selected!!!")<br />
method_selection.activated[str].connect(do_somethinh)@</p>
]]></description><link>https://forum.qt.io/post/248999</link><guid isPermaLink="true">https://forum.qt.io/post/248999</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sat, 25 Oct 2014 23:02:53 GMT</pubDate></item><item><title><![CDATA[Reply to PySide: Connecting QComboBox indices with strings on Sat, 25 Oct 2014 20:58:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">AFAIK (haven't used PyQt/PySide for while)</p>
<p dir="auto">@<br />
def do_something(self, index):<br />
print "{} has been selected!!!".format(self.itemText(index))<br />
@</p>
<p dir="auto">should to it</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/248984</link><guid isPermaLink="true">https://forum.qt.io/post/248984</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 25 Oct 2014 20:58:51 GMT</pubDate></item></channel></rss>