0

I have list of check box objects which was created dynamically (runtime). Now how can i set signal check for all these objects in runtime? I'm using pyqt4 for developing. i tried 'for loop' with objects, but signal check is set only to last object of that list. But i need to set signal check for all objects.

obj = widget()
count = 0
while(count<4):
        self.listOfObjs.append(QtGui.QCheckBox(obj.gridFrame))
        obj.gridLayout.addWidget(self.listOfObjs[count], count, 1)
        count = count + 1
for i in listOfObjs:
    i.stateChanged.connect(self.change)

def change():
     *****DO NECCESSARY THINGS*****
Anand
  • 343
  • 1
  • 5
  • 18
  • For me the code you show is correct, I think the error is elsewhere, you could provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – eyllanesc Aug 10 '17 at 09:47
  • You could show more code, please. – eyllanesc Aug 10 '17 at 09:56
  • understandable ? @eyllanesc – Anand Aug 10 '17 at 09:59
  • try Change `QtGui.QCheckBox(obj.gridFrame)` to `QtGui.QCheckBox(obj.gridFrame, obj)` As many times the garbage collector eliminates variables. – eyllanesc Aug 10 '17 at 10:02
  • Also try changing to `def change(state):` – eyllanesc Aug 10 '17 at 10:03
  • This is all I can suggest as I see that you can not provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – eyllanesc Aug 10 '17 at 10:05
  • Got following error:TypeError: arguments did not match any overloaded call: QCheckBox(QWidget parent=None): too many arguments QCheckBox(QString, QWidget parent=None): argument 1 has unexpected type 'QFrame' – Anand Aug 10 '17 at 10:06
  • If your code was an mvce I could copy your code and execute it without any problem, but that is not your case. – eyllanesc Aug 10 '17 at 10:06
  • See also https://stackoverflow.com/questions/12173153/qt-dynamic-widgets-signal-and-slot-connection?rq=1 – NoDataDumpNoContribution Aug 11 '17 at 07:58

0 Answers0