Skip to content Skip to sidebar Skip to footer

Is There Any Way To Remove A Qwidget In A Qgridlayout?

What I want is to completely remove a widget (purge it, delete it, etc...), but it's in a gridlayout, so even when calling removeWidget, it still keeps a pointer, so python doesn't

Solution 1:

Layouts re-parent the widgets to the containers. So even if you remove it from the layout, container widget is still the parent, so that widget is not removed. You should call .deleteLater() to tell Qt to get rid of that widget (effectively clearing all references for the widget so that Python can purge it):

defremRow(self, row):
    self.gridlayout.removeWidget(self.entries[row])
    self.entries[row].deleteLater()
    del self.entries[row]

Solution 2:

If you want to just get rid of the widget for good, just delete it. From Python, you may have to call widget's deleteLater() method. Qt should take care of the rest, like removing it from layout etc.

I'm not sure what the del in your question does, but apparently it does not do C++ delete.

Post a Comment for "Is There Any Way To Remove A Qwidget In A Qgridlayout?"