A question about adding to layout
I want to add childWidgets to a layouted parentWidget at runtime. I need to construct the children like
Code:
ChildWidget* child = new ChildWidget(parentWidget);
right? So now I would expect the child to be layed out according to the parentWidget's layout, but it doesn't happen. It seems like I explicitely have to:
Code:
ChildWidget* child = new ChildWidget(parentWidget);
parentWidget->layout()->addWidget(child);
Is this the right way? It feels like I'm adding the child to the parent twice.
Re: A question about adding to layout
Quote:
Originally Posted by
Cruz
Is this the right way? It feels like I'm adding the child to the parent twice.
you do right. if a child has no parent then QLayout::addWidget set parent, in another if a child has a parent, has been layouted and that parent not equal to the layout's parent then QLayout::addWidget you'll an error on console.
Quote:
qWarning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent",
w->metaObject()->className()