Resolving conflicts with PyQt new-style signals-slots

£可爱£侵袭症+ 提交于 2019-12-07 04:21:00

问题


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?


回答1:


See the second example in connecting signals portion of documentation.

In your case it would be:

self.myComboBox.currentIndexChanged[QtCore.QString].connect(self.mySlot)

or if you are using v2 API for QString

self.myComboBox.currentIndexChanged[str].connect(self.mySlot)



回答2:


You must specify the return value within brackets if you want non-default value to be returned

self.myComboBox.currentIndexChanged[str].connect(self.mySlot)

def mySlot(self, item):
    self.currentItem = item

see : http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html



来源:https://stackoverflow.com/questions/9268786/resolving-conflicts-with-pyqt-new-style-signals-slots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!