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

addLayout() should reparent the added layout

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Open
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: 4.8.0
    • Fix Version/s: None
    • Component/s: Widgets: Layout
    • Labels:
      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

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

            Activity

              People

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

                Dates

                • Created:
                  Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes