[PyQt] QWidget not deleted with its parent window
Tavian Barnes
tavianator at tavianator.com
Thu Nov 3 23:49:03 GMT 2011
I originally posted this on stackoverflow[1], where I learned that
this seems to be a bug in PyQt 4.8.6. (I'm using Qt 4.7.4 if that's
relevant.)
Basically, the __del__ method of the central widget of a window is
never called. Example:
#!/usr/bin/env python
from PyQt4 import QtGui
class Preview(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
def __del__(self):
print("Deleting Preview")
class PreviewWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.widget = Preview(self)
self.setCentralWidget(self.widget)
def __del__(self):
print("Deleting PreviewWindow")
if __name__ == "__main__":
app = QtGui.QApplication(["Dimension Preview"])
window = PreviewWindow()
window.show()
app.exec()
# del window
If I uncomment the "del window" line, "Deleting Preview" prints as
expected. Otherwise, I just see "Deleting PreviewWindow". Apparently
pyqt 4.8.5 works correctly.
[1] http://stackoverflow.com/questions/7988578/qwidget-not-deleted-with-parent-window
--
Tavian Barnes
More information about the PyQt
mailing list