KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the 'correct' or idiomatic way to cleanup/delete widgets when using PyQt4? Consider the following code: choices = ['a', 'b', 'c'] checkboxes = [] layout = QtGui.QVBoxLayout() dialog = MyDialog() for c in choices: checkboxes.append(QtGui.QCheckBox(c) layout.addWidget(chkbox) dialog.setLayout(layout) for c in checkboxes: c.setParent(None) c.deleteLater() c = None The above code uses setParent() , deleteLater() , and setting the object to None . Are all of these necessary? Another possible scenario is I have a dialog with a bunch of widgets on it and want to remove these widgets and add new ones. I don't want to 'leak' the old widgets, but I'm not sure what the correct way to do something like this would be. It seems to me that deleteLater() might never be needed. Does it just decrement the reference count? If so, wouldn't just setting the variable to None do the same thing?
Tags (comma-separated)
Save Edits
Cancel