[PyQt] Deleting a PyQt object

Mark Summerfield mark at qtrac.eu
Thu Nov 22 08:43:00 GMT 2007


On 2007-11-22, Fabian Steiner wrote:
> Hello!
>
> I'm currently working on a programm which adds a QTableWidget to an
> existing QGridLayout using QGridLayout.addWidget(). When the user pushes
> button btn1, this QTableWidget should disappear and the layout should free
> the space.
>
> In order to achieve this aim I tried the following:
>
> [...]
> self.ui.gridlayout.removeWidget(self.legend)
> del self.legend
> [...]
>
> => The QTableWidget is indeed removed from the layout, but still exists in
> the GUI.
>
> [...]
> self.ui.gridlayout.removeWidget(self.legend)
> import sip
> sip.delete(self.legend)
> [...]
>
> => works as expected
>
> Is this really the right way to do it? Why doesn't the del-approach work?
> Actually no other PyQT objects should hold any other references to
> self.legend.

After self.legend was laid out, when the setLayout() call was made on
the widget it appears in, it was automatically reparented to that
widget, so even if you remove it from the layout its parent still has a
reference to it.

-- 
Mark Summerfield, Qtrac Ltd., www.qtrac.eu



More information about the PyQt mailing list