Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First thing you should remember to do is to use the parent/child relationships for your widgets. When you do this, they will be owned by Qt and will automatically clean up all children when the parent is deleted. </p> <pre><code>dialog = MyDialog() for c in choices: checkboxes.append(QtGui.QCheckBox(c, parent=dialog)) layout.addWidget(chkbox) </code></pre> <p>In this situation, all the checkboxes will be properly cleaned up when you delete dialog. This handles one part of your question. I realize that you are implicitly having the parent set when you add them to the layout. But you should not then clear that parent before deleting. It <strong>is</strong> the parent relationship that allows the child to be automatically removed. Not a reference count. The reference aspect would be a python-side thing where it will get garbage collected when there are no more references to it. </p> <p><code>deleteLater</code> is very important, for use when you want the deletion to occur when control returns to the eventloop. It is also the safe way to delete widgets when you are removing some from a layout and adding new ones:</p> <pre><code># clear a layout and delete all widgets # aLayout is some QLayout for instance while aLayout.count(): item = aLayout.takeAt(0) item.widget().deleteLater() </code></pre> <p>These widgets will actually be deleted once this method has completed. <code>deleteLater</code> is also useful for deleting the widget under which the slot or event is currently occurring. Such as a QPushButton that can delete itself on click.</p> <p>There is also not much need to set <code>c = None</code>. Once a parent is deleted, and that triggers the deletion of all of its children, recursively, your python references to that object will be invalid. So all you need to do is to just not use them anymore. If they are in a list, clear the list. Accessing them would raise the <code>RuntimeError: wrapped C/C++ object of %S has been deleted</code> meaning they are deleted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload