pythonqtwidgetpyqt

pyqt: how to remove a widget?


I have a QGroupBox widget with children in it that I want to remove. How do I do that? I can't find any removeWidget, removeChild, removeItem, or anything similar in the docs. I can only see how to remove things from a layout, but that, apparently, doesn't remove it from the actual widget.


Solution

  • Well, this works: on the widget you want to remove, call widget.setParent(None). I like how adding to a layout adds a widget to the container, but removing from a layout doesn't... fun stuff.