Conflict Resolution with New Style PyQt Signal Slots

QComboBox has two signals, both called currentIndexChanged ; one passes the index of the selected item, and the other transfers 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 that I can use new-style signals to indicate that I want to return text?

+4
source share
2 answers

See the second example in the connection signals documentation.

In your case, it will be:

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

or if you use v2 API for QString

 self.myComboBox.currentIndexChanged[str].connect(self.mySlot) 
+7
source

You must specify the return value in parentheses if you want to return a value other than the default value.

 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

+4
source

Source: https://habr.com/ru/post/918842/


All Articles