How to move a layout to a new parent?
Is is possible to re-parent a layout? I've been trying to do it all day but have not had any success. Here are the details:
I have a group of widgets (a couple text edits and labels) that form a UI element in my app. I have them grouped in a VBoxLayout. Sometimes (depending on the options the user selects) I want this group to show up on a particular TabWidget tab that's a child of my dialog. Sometimes I want the group to show up directly on the dialog, with the TabWidget hidden.
To put it graphically, sometimes I want MyMovableLayout to appear in this hierarchy:
QDialog -> TopLayout -> QTabWidget -> Tab -> MyMovableLayout
and sometimes I want:
QDialog -> TopLayout -> MyMovableLayout.
I've tried a variety of setParent()/addLayout()/insertLayout()/show()/hide() combinations, but nothing seems to work. I can never get the layout to show up under the TopLevel layout.
Nope, there is no such method. I would suggest you group the items as a widget instead of in just a layout. Just apply the layout to that new widget, and put the content-widgets in that layout. Now, you can reparent the whole widget in one go.
on a side note: this is my 2^12 post on DevNet! I made it just before the move to qt-project.org :-)