[Interest] Taking back a widget from a QBoxLayout?
jhihn at gmx.com
Fri Feb 22 21:19:24 CET 2019
> Sent: Friday, February 22, 2019 at 3:10 PM
> From: "Matthew Woehlke" <mwoehlke.floss at gmail.com>
> To: "Jason H" <jhihn at gmx.com>, "interest at qt-project.org" <interest at qt-project.org>
> Subject: Re: Taking back a widget from a QBoxLayout?
> On 22/02/2019 14.42, Jason H wrote:
> >>> https://doc.qt.io/qt-5/layout.html#tips-for-using-layouts
> > From that:
> > '''
> > When you use a layout, you do not need to pass a parent when
> > constructing the child widgets. The layout will automatically
> > reparent the widgets (using QWidget::setParent()) so that they are
> > children of the widget on which the layout is installed.
> > Note: Widgets in a layout are children of the widget on which the
> > layout is installed, not of the layout itself. Widgets can only have
> > other widgets as parent, not layouts.> '''
> > However:
> > '''
> > void QLayout::addItem(QLayoutItem *item)
> > [...]
> > Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
> > void QLayout::addWidget(QWidget *w)
> > Adds widget w to this layout in a manner specific to the layout. This function uses addItem().
> > '''
> ...but that's talking about a *QLayoutItem*, which is *not* a QWidget
> (or even a QObject). It's a class that encapsulates a "thing" (widget,
> other layour, spacer, ...) that is present in a QLayout.
> Let's say you have widgets P and C, with P having layout L which
> contains C.
> P "owns" C and (AFAIK) L.
> There *also* exists a layout item I. L owns I. I *references*, but does
> not own, C.
I am with you, but confused by "This function uses addItem()." Since addItem is used to QLayout*, I don't see how this is possible?
More information about the Interest