謝謝Oleh Prypin!當我在PySide文檔中遇到晦澀難懂的arg__1時,你的答案對我有幫助。
當我同時測試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
對於信號特徵的目的。
希望能幫助別人!