[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Deleting a layout in PyQt as opposed to Qt...
From:       Giovanni Bajo <rasky () develer ! com>
Date:       2007-02-28 11:39:49
Message-ID: 45E56A05.7090801 () develer ! com
[Download RAW message or body]

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)
-- 
Giovanni Bajo

_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic