Qt About using layouts, widget parenting

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

The layouts are a necessary in every Qt application. They manage the object, their position, their size, how they are resized.

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.



Got any Qt Question?