views:

90

answers:

2

I'm working on a PyQt application. Currently, there's a status panel (defined as a QWidget) which contains a QHBoxLayout. This layout is frequently updated with QPushButtons created by another portion of the application.

Whenever the buttons which appear need to change (which is rather frequently) an update effect gets called. The existing buttons are deleted from the layout (by calling layout.removeWidget(button) and then button.setParent(None)) and the new buttons are added to the layout.

Generally, this works. But occasionally, when I call button.setParent(None) on the button to delete, it causes it to pop out of the application and start floating in its own stand-alone frame.

How can I remove a button from the layout and ensure it doesn't start floating?

+2  A: 

You should call the button's close() method. If you want it to be deleted when you close it, you can set the Qt.WA_DeleteOnClose attribute:

button.setAttribute(Qt.WA_DeleteOnClose)
Luper Rouch
+2  A: 

Try calling QWidget::hide() on the button before removing from the layout if you don't want to delete your button.

gregseth