Qt 之 Layout
直接贴 Qt 帮助里的原话吧
Tips for Using Layouts
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.
You can nest layouts using addLayout() on a layout; the inner layout then becomes a child of the layout it is inserted into.
QLayout 会负责将每个在 QLayout 中布局的 QWidget 对象 和 QLayout 本身所在的父 QWidget 对象进行“连接”,也就是将这些布局对象转变为本身坐在的父 QWidget 对象的孩子,由它来负责各个布局子对象的生存期管理。 容易错误以为 QLayout 会是这些布局对象的父母,但是事实上它们之间应该是兄弟关系,QLayout 只负责将这些布局对象跟其父母进行连接而已。