Han*_*ans 5 qt pyqt signals-slots
QComboBox有两个信号,都叫currentIndexChanged; 一个传递所选项目的索引,另一个传递所选项目的文本.当我将这个信号连接到我的插槽时,有类似的东西self.myComboBox.currentIndexChanged.connect(self.mySlot)给了我一个索引.有没有办法可以使用新式信号来表明我想要返回的文字?
在你的情况下,它将是:
self.myComboBox.currentIndexChanged[QtCore.QString].connect(self.mySlot)
Run Code Online (Sandbox Code Playgroud)
或者如果您使用的是v2 API QString
self.myComboBox.currentIndexChanged[str].connect(self.mySlot)
Run Code Online (Sandbox Code Playgroud)
如果要返回非默认值,则必须在括号内指定返回值
self.myComboBox.currentIndexChanged[str].connect(self.mySlot)
def mySlot(self, item):
self.currentItem = item
Run Code Online (Sandbox Code Playgroud)
请参阅:http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html