[OT] Re: [PyKDE] Deleting a layout in PyQt as opposed to Qt...

Hans-Peter Jansen hpj at urpla.net
Wed Feb 28 12:38:26 GMT 2007


[Since this is essentially off topic, it's intentionally top posted!]

Hi Giovanni,

did I already told you, that I LOVE your contributions to this project and 
list! While nobody will be able to beat Phils S/N ratio ever, David Boddie 
and you are my personal PyQt heros.

Pete

Am Mittwoch, 28. Februar 2007 12:39 schrieb Giovanni Bajo:
> On 28/02/2007 12.17, Sundance wrote:
> > Am I missing something? Is this an oversight in PyQt, or is there a
> > nice, clean Python equivalent that I've overlooked?
>
> With recent versions of SIP, you can do:
>
> import sip
> sip.delete(widget.layout())
>
> =================
>
> Otherwise, if you're bound to an older version, a less clear but
> effective way is to force SIP to transfer ownership of the object back to
> Python. By doing so, you tie the lifetime of the C++ object to the
> lifetime of the Python object:
>
> import sip
> L = widget.layout()
> sip.transferback(L)
> del L   # drop last Python reference -> destroy C++ object
>
> Or, a more compact but equivalent form:
>
> import sip
> sip.transferback(widget.layout())
>
> Of course, for this to work, you need to make sure you don't have *any*
> other Python reference to that layout.
>
> =================
>
> A third solution involves the fact that QLayout is a QObject, so you can
> use its deleteLater() method:
>
> L = widget.layout()
> L.deleteLater()
> QCoreApplication.sendPostedEvents(L, QEvent.DeferredDelete)




More information about the PyQt mailing list