On Thu, 10 May 2012 19:50:37 +1200, Stephan Aßmus <superstippi@xxxxxx> wrote:
So what is your proposed solution that you have to call AddChild() to add the views to the parent in the first place? In the current solution, you don't have to do that and I find your proposed change would add a lot of overhead to the common case, while it enables a corner case that could also be solved by other means.parent->RemoveItem(fLayout1); parent->AddItem(fLayout2, ...); This removes fLayout1 and all views from the target view and adds fLayout2 and all child views again. You can also switch it back: parent->RemoveItem(fLayout2); parent->AddItem(fLayout1, ...); So only if the layout is attached to a target also the child items are guaranteed to be attached to the same target view.
I see no problem here, you don't have to call AddChild at all, the layout still adds views if needed. If the layout is attached to a parent and a child view is added to the layout, the layout adds the child to the parent as well. If the layout is not attached to a parent view newly added views are also not added to any view. Only when this detached layout is added to a target view all layout child are added. So nothing changes with this approach. For an example see *) again. (from that you can also see that you don't have to specify a parent in the QWidget constructor)
Cheers, Clemens *) http://qt-project.org/doc/qt-4.8/QGroupBox.html