python 2.7 - Converting from PyQt4 signal to PyQt5 signal doesn't work -


i trying convert game pyqt4 pyqt5 , having difficulty converting newer signal types. have gone original , trying convert signal first using pyqt4. commented line old (working) version, underneath new version. 'new' version passing same value event handler: 0. have tried many subtly different versions, nothing seems work. ideas?

    self.cellbuttonnames = [self.ui.cell0button,  self.ui.cell1button,  self.ui.cell2button,  self.ui.cell3button,  self.ui.cell4button,  self.ui.cell5button,                                         self.ui.cell6button, self.ui.cell7button,  self.ui.cell8button,  self.ui.cell9button,  self.ui.cell10button,  self.ui.cell11button,                                          self.ui.cell12button,  self.ui.cell13button,  self.ui.cell14button,  self.ui.cell15button,  self.ui.cell16button,  self.ui.cell17button,                                          ...,                                         self.ui.cell126button,  self.ui.cell127button,  self.ui.cell128button,  self.ui.cell129button,  self.ui.cell130button,  self.ui.cell131button,                                         self.ui.cell132button,  self.ui.cell133button,  self.ui.cell134button,  self.ui.cell135button,  self.ui.cell136button,  self.ui.cell137button,                                         self.ui.cell138button,  self.ui.cell139button,  self.ui.cell140button,  self.ui.cell141button,  self.ui.cell142button,  self.ui.cell143button]      # connect of ball buttons 1 slot (event handler) , pass cell number event handler when signalled.     # elimates need 144 event handling methods! :-)      cellnumber = 0     buttonname in self.cellbuttonnames:         # self.connect(buttonname, qtcore.signal("clicked()"), lambda who=cellnumber: self.ballclicked(who))         buttonname.clicked.connect(lambda who=cellnumber: self.ballclicked(who))         cellnumber += 1  @qtcore.pyqtsignature("")                                                                           # otherefore want ne signal autoconnect. def ballclicked ( self, cellnumber):     print("ball %i clicked" % cellnumber) 

this quite well-known "gotcha".

there few signals (like clicked , triggered) have default parameter sends value. buttons , actions, bool representing current checked state (even though may not have been set checkable).

to work around this, can connect signals this:

    buttonname.clicked.connect(         lambda checked, who=cellnumber: self.ballclicked(who)) 

however, in particular case, might want consider using qbuttongroup instead. require one signal connection, and, side-benefit, you'd ready-made interface managing buttons.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -