Reputation: 90329
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 QPushButton
s 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?
Upvotes: 3
Views: 342
Reputation: 13448
Try calling QWidget::hide()
on the button before removing from the layout if you don't want to delete your button.
Upvotes: 2
Reputation: 9502
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)
Upvotes: 2