Important: Please read the Qt Code of Conduct -

PySide: Connecting QComboBox indices with strings

  • 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").

    I am new to PySide and learning, so I am sure there exists a simple solution. Help is appreciated.

    @from PySide import QtGui

    class Widget(QtGui.QWidget):
        def __init__(self, parent=None):
            v_global_layout = QtGui.QVBoxLayout()
            method_selection = QtGui.QComboBox()
            def do_somethinh():
                print("A has been selected!!!")
    if __name__ == '__main__':
        import sys
        app = QtGui.QApplication(sys.argv)
        main_window = Widget()
        main_window.setGeometry(100, 100, 640, 480)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK (haven't used PyQt/PySide for while)

    def do_something(self, index):
    print "{} has been selected!!!".format(self.itemText(index))

    should to it

    Hope it helps

  • Thsnk you!

    I also found another way to do it:

    @def do_somethinh(text):
    print(text, "has been selected!!!")

  • Lifetime Qt Champion

    You're welcome !

    Yes, that's also a good solution

    Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

Log in to reply