[PyQt] Correct way to delete Qt objects from PyQt?

Damon Lynch damonlynch at gmail.com
Tue Feb 9 10:58:57 GMT 2016

To minimize memory use and to avoid segfaults at program exit, when
deleting PyQt objects should one use:


or simply


or both, or something else?

I have come across this issue in my code because of a serious problem
maintaining the correct layout of child widgets within a QSplitter. In this
particular case widgets can be hidden and shown by way of a toggle switch:

Upon activating the toggle switch, if I do not destroy the QWidget that
lays out the widgets above the splitter handle (immediately above the
timeline), and replace it with a new instance of the same QWidget, the
layout of the child widgets is badly wrong with respect to vertical
alignment within the layout and  minimum widget size. If I merely replace
the parent QWidget's layout with .setLayout(), for example, the layout only
becomes correct only when the user resizes the application window or moves
the splitter handle. Therefore as best I can tell, the existing instance of
the QWidget must be replaced every time  a child widget is hidden / shown.
Whether this is peculiar to child widgets in QSplitter children, I cannot

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160209/68226935/attachment.html>

More information about the PyQt mailing list