Yes, this is normal behavior . And they fall not on the layout, but on the QWidget (the parent, the one that this ).
If parent is 0, the new widget becomes a window. If parent is another widget, this widget becomes a child window inside parent .
Layout itself assigns the parent to widgets, and itself only controls their positioning.
When constructing the child widgets. The layout will automatically replicate the widgets (using QWidget :: setParent ()).
How to correctly write out here .
Example:
QWidget *window = new QWidget; QPushButton *button1 = new QPushButton("One"); QLineEdit *lineEdit1 = new QLineEdit(); QPushButton *button2 = new QPushButton("Two"); QLineEdit *lineEdit2 = new QLineEdit(); QPushButton *button3 = new QPushButton("Three"); QLineEdit *lineEdit3 = new QLineEdit(); QFormLayout *layout = new QFormLayout; layout->addRow(button1, lineEdit1); layout->addRow(button2, lineEdit2); layout->addRow(button3, lineEdit3); window->setLayout(layout); window->show();