class Widget(QtGui.QWidget):

    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)
self.destroyed.connect(self.handleDestroyed)

def __del__(self):
    print(('__del__:', self))

def handleDestroyed(self, source):
    print(('destroyed:', source))


class Foo(Widget):

    def __init__(self, parent):
        Widget.__init__(self, parent)


class Bar(Widget):

    def __init__(self, parent):
        Widget.__init__(self, parent)


class Window(Widget):

    def __init__(self, parent=None):
        Widget.__init__(self, parent)
self.foo = Foo(self)
self.bar = Bar(None)
if __name__ == '__main__':
    app = QtGui.QApplication([__file__, '-widgetcount'])
window = Window()
window.show()
app.exec_()
QWidget not deleted with parent window