Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving conflicts with PyQt new-style signals-slots

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?

like image 344
Hans Hermans Avatar asked Feb 13 '12 22:02

Hans Hermans


2 Answers

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)
like image 140
Avaris Avatar answered Oct 29 '22 18:10

Avaris


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

like image 36
NotCamelCase Avatar answered Oct 29 '22 18:10

NotCamelCase