[PyKDE] Destroying pyqt child widgets

Boudewijn Rempt boud at valdyas.org
Fri Nov 16 20:47:48 GMT 2001


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 16 November 2001 19:11, Brent Burley wrote:
> How does one destroy a child widget in pyqt?  If you completely deref a
> top level widget, it and all its children will be destroyed.  But what
> if you only want to destroy the child and not its parent?
>
> In C++ you can just say "delete child;" and qt will destroy it and
> remove it from its parent.  But there's no equivalent in pyqt.
>
> In python you can do "child.destroy()" but this only frees with window
> system resources and leaves the child widget there.  This is bad and can
> make Qt do some pretty strange things.  In fact, QWidget::destroy is
> protected in C++ and shouldn't even be callable; it's normally only
> called by the QWidget destructor.
>
> I've come up with this workaround:
>
>   def deleteQWidget(w):
>     w.reparent(QWidget(), 0, QPoint())


What I do if I really want to delete a widget (one that doesn't
react correctly to the WM_Destructive_Close or whatever it's called
hint, so close() doesn't destroy it), is w.parent.removeChild(w).
It's simple and very effective :-).

- -- 
Boudewijn Rempt | http://www.valdyas.org
public key at: certserver.pgp.com  or pki.surfnet.nl
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE79WylN8fj6DnPxOgRAk6kAJ0RNaN5fPwnEyQa5g/tOlY/J0AYSQCfaiWa
/4pLiodpHoRWc42rEcYm/E0=
=RhCC
-----END PGP SIGNATURE-----




More information about the PyQt mailing list