python - Passing Arguments with Newstyle signals in PyQT -


I have a problem with the set of dynamically created buttons in PyQT.

I am using a list to create buttons corresponding to different values. Since each button is different, I need to give them an argument to differentiate them on the "button click", so I can take various actions with them. Even I have so far:

  In X for myself Button: name = str (x) button = qtguii CushButton (frame) button .set text (name) cp_result = self.changeProject (name) if cp_result is none: print 'changeProject (% s) none!', Name else: print 'changeProject (% s) is OK (% R) ', name, cp_result # button.clicked.connect (cp_result) Setattr (self, "btn_% s"% name, button) self.btnList.append (button) def change project (auto, name): x For self.btnList: If x.isDown: # Change UI Frame to blahblah return 'A string' Working with Alex, this is the latest code, the return value on the change position of the fairy Shn, which clearly can not be a string, but I still need to determine which button is pressed in the middle. Auto-generated buttons  

Current error: TypeError: connect () slot argument should be a callable or a signal, not 'str'

< Div class = "post-text" itemprop = "text">

You can add dynamic to objects by using setattr

  in the button : Name = str (x) button = QtGui.QPushButton (frame) button. Settext (name) button.clicked.connect (self.changeProject (name)) setattr (self, "btn_% s"% name, button)  

Comments