PyQt5: nested layouts

Rodrigo de Salvo Braz rodrigobraz at gmail.com
Fri Apr 30 00:31:13 BST 2021


Hi Rich,

The problem occurs at line

row1 = qtw.QHBoxLayout(self)

When you create a layout with a QWidget argument (here, self), you are
saying that this will be the layout for that widget. However, you had
already done the same for the inner layout:

inner = qtw.QVBoxLayout(self)

so self already had a layout.

To fix it, you simply need to create row1 without the argument self:

row1 = qtw.QHBoxLayout(self)  # no argument

Hope that helps.

Rodrigo

On Thu, Apr 29, 2021 at 2:39 PM Rich Shepard <rshepard at appl-ecosys.com>
wrote:

> I thought that I understood how to nest layouts, but I'm getting an error:
> $ python test.py
> QLayout: Attempting to add QLayout "" to TestWindow "", which already has
> a layout
>
> When the test.py module used a grid layout with a container named,
> 'container', there was no problem. But, trying to replace the grid with a
> series of QHBoxLayout within a QVBoxLayout the above warning displays. I'm
> not seeing why. The test.py file is attached.
>
> Please show me what I've done incorrectly.
>
> Rich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210429/3d51dca1/attachment.htm>


More information about the PyQt mailing list