qt布局添加控件的父控件说明

Remarks

From Qt layout documentation:

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.

So do :

QGroupBox *box = new QGroupBox("Information:", widget);
layout->addWidget(box);

or do :

QGroupBox *box = new QGroupBox("Information:", nullptr);
layout->addWidget(box);

is exactly the same.

posted @ 2020-07-24 11:25  beautifulday  阅读(909)  评论(0编辑  收藏  举报