Overloaded pyside signals (QComboBox)

Using QComboBox with pyside, I know how to connect a signal and use the index that it sends. But what about the unicode argument? If I prefer to connect to what the string from the drop-down list wants, is this possible?

C: http://www.pyside.org/docs/pyside/PySide/QtGui/QComboBox.html#PySide.QtGui.QComboBox

All three signals exist in two versions: one with the argument PySide.QtCore.QString and one with the argument int.

Signals

def activated (arg__1)
def activated (index)

PySide.QtGui.QComboBox.activated (index) Parameters: index - PySide.QtCore.int

PySide.QtGui.QComboBox.activated (arg_1) Parameters: arg_1 - unicode

Edit: code.

le = ComboBoxIpPrefix()
le.currentIndexChanged.connect(lambda x....)

This code gives me an index. The question was how to get the unicode string specified in the docs.

+5
2

, .

QComboBox.activated. , .

PySide, :

a_combo_box.activated[int].connect(some_callable)

a_combo_box.activated[str].connect(other_callable)

, , Python 2, str unicode.

, (++) Qt-, PySide : arg__1...
"" Python . , QString str ( unicode Python 2, , , Python, text, str Py3 unicode Py2); long, short .. int; double float; QVariant , , ; ...

+12

! , arg__1 PySide.

combo.currentIndexChanged [str], combo.currentIndexChanged [unicode], Unicode .

, :

from PySide import QtCore
from PySide import QtGui

class myDialog(QtGui.QWidget):
    def __init__(self, *args, **kwargs):
        super(myDialog, self).__init__(*args, **kwargs)

        combo = QtGui.QComboBox()
        combo.addItem('Dog', 'Dog')
        combo.addItem('Cat', 'Cat')

        layout = QtGui.QVBoxLayout()
        layout.addWidget(combo)

        self.setLayout(layout)

        combo.currentIndexChanged[int].connect(self.intChanged)
        combo.currentIndexChanged[str].connect(self.strChanged)
        combo.currentIndexChanged[unicode].connect(self.unicodeChanged)

        combo.setCurrentIndex(1)

    def intChanged(self, index):
        print "Combo Index: "
        print index
        print type(index)

    def strChanged(self, value):
        print "Combo String:"
        print type(value)
        print value

    def unicodeChanged(self, value):
        print "Combo Unicode String:"
        print type(value)
        print value

if __name__ == "__main__":

    app = QtGui.QApplication([])
    dialog = myDialog()
    dialog.show()
    app.exec_()

:

Combo Index
1
<type 'int'>
Combo String
<type 'unicode'>
Cat
Combo Unicode String
<type 'unicode'>
Cat

, basestring IndexError: Signature currentIndexChanged(PyObject) not found for signal: currentIndexChanged. PySide, -, int, float ( double), str/unicode ( unicode) bool, python PyObject .

, -!

+2

All Articles