解决与 PyQt 新式信号槽的冲突
问题描述:
QComboBox
有两个信号,都称为 currentIndexChanged
;一个传递所选项目的索引,另一个传递所选项目的文本.当我将此信号连接到我的插槽时,使用诸如 self.myComboBox.currentIndexChanged.connect(self.mySlot)
之类的东西,它会给我一个索引.有没有办法可以使用新样式的信号来指示我希望返回文本?
QComboBox
has two signals, both called currentIndexChanged
; one passes the index of the selected item, and the other passes the text of the selected item. When I connect this signal to my slot, with something like self.myComboBox.currentIndexChanged.connect(self.mySlot)
it gives me an index. Is there a way I can use new-style signals to indicate that I want the text returned?
答
参见 连接信号部分 文档.
在你的情况下是:
self.myComboBox.currentIndexChanged[QtCore.QString].connect(self.mySlot)
或者如果您使用的是 QString
self.myComboBox.currentIndexChanged[str].connect(self.mySlot)