Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
4.8.0
-
None
Description
QBoxLayout::addLayout() and QGridLayout::addLayout() functions should reparent the added layout automatically if it already has a parent. Currently these functions call QLayout::addChildLayout() which does not add the child layout if it already has been added to some other layout i.e. has a parent.
Please note that QBoxLayout::addWidget() and QGridLayout::addWidget() reparent the added widget. Thus there is an inconsistency on the functionality.
Example which demonstrates the use case:
#include <QtGui> int main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget w; QHBoxLayout* masterLayout = new QHBoxLayout; w.setLayout(masterLayout); QGridLayout* gridLayout = new QGridLayout; masterLayout->addLayout(gridLayout); QHBoxLayout* tmpLayout = new QHBoxLayout; tmpLayout->addWidget(new QLabel("Name")); tmpLayout->addWidget(new QLineEdit ); gridLayout->addWidget(new QLabel("spacer"),1, 0); gridLayout->addLayout(tmpLayout, 2, 0); // does not add the layout as it already has a parent // warning note: "QLayout::addChildLayout: layout "" already has a parent" masterLayout->addLayout(tmpLayout); w.show(); return app.exec(); }
Attachments
Issue Links
- relates to
-
QTBUG-30758 QBoxLayout::insertLayout() crashes if other layout already has parent
- Closed