Issue
I have got a loop. I created a QCheckBox
and put it in a QTableWidget
cell, and everything is Ok. In each step of loop I have called a connect
function, for myslot SLOT, but only the last QCheckBox
instance is applied. I googled a lot and have found many people have my problem. I have applied their solutions, but my problem remains.
for row in xrange(len(uniqueFields)):
instance = QtGui.QCheckBox(uniqueFields[row], findInstance.tableWidget)
print QtCore.QObject.connect(instance,
QtCore.SIGNAL(_fromUtf8("stateChanged (int)")),
lambda: findInstance.projectsInstance.myslot(
"TWCH", findInstance, instance.text(),
instance.checkState(), instance))
findInstance.tableWidget.setRowCount(findInstance.tableWidget.rowCount() + 1)
findInstance.tableWidget.setCellWidget(row, 0, instance)
Note: my connect
function return True
.
How to create connect
function in a loop that enumerates all of the instances
?
Solution
I have same problem , you should use functools.partial
such as:
for key, val in a_DICT_THAT_YOU_STORED_YOUR_OBJECTS_AND_STRINGS:
obj = partial( findInstance.projectsInstance.myslot,arg1="TWCH",arg2=self,arg3=key,arg4=val.checkState() )
QtCore.QObject.connect(val, QtCore.SIGNAL(_fromUtf8("stateChanged (int)")), obj)
Of course, argX should set to your real name of your argument of your function name.
Answered By - PersianGulf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.