Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-24420

addLayout() should reparent the added layout

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.8.0
    • Widgets: Layout
    • None

      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();
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            qtcomsupport Qt Support
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes