PDA

View Full Version : A question about adding to layout



Cruz
20th January 2009, 12:31
I want to add childWidgets to a layouted parentWidget at runtime. I need to construct the children like



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:



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.

spirit
20th January 2009, 12:41
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.


qWarning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent",
w->metaObject()->className()