谢谢奥莱普里平!当我在 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
信号签名的目的。
希望对某人有所帮助!