[PyQt] Re: Adding a widget to a layout that belongs to a QGroupBox

Nate Reid nreid at imagemoversdigital.com
Fri Aug 14 18:35:18 BST 2009


Thank you... I realized in my testing of other widgets that this was the case.  It appears that if we want to keep a reference to the 'original' parent, it must be set explicitly as an argument to the constructor/init, or set as an attribute later.  Unless you have a more elegant way to get around the re-parenting issue.
-Nate

-----Original Message-----
Date: Fri, 14 Aug 2009 08:39:09 +0200
From: Andreas Pakulat <apaku at gmx.de>
Subject: Re: [PyQt] Adding a widget to a layout that belongs to a
	QGroupBox	changes that widget's parent?
To: pyqt at riverbankcomputing.com
Message-ID: <20090814063909.GB24538 at trinity.apaku.dnsalias.org>
Content-Type: text/plain; charset=us-ascii

On 13.08.09 15:34:44, Nate Reid wrote:
> I'm using PyQt 4.5.1
> 
> For some reason the parent is changing, but only when a QGroupBox is used...

No, if you have widget A added to a layout thats set on widget B and
widget A's parent is not widget B then A is _always_ reparented to B.
The code for that is in qwidget.cpp and qlayout.cpp. IIRC this is also
documented in the QLayout api docs.

> Another odd thing is that if I uncomment out the line "self.layout.addWidget(self.box), it crashes (e.g. stalls out completely, and I have to kill the shell)

Recursive layouts are not supported by Qt, i.e. you can't add the box to
the box' layout.

Andreas

-- 
Blow it out your ear.


------------------------------



More information about the PyQt mailing list