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

QFormLayout: impossible to remove rows

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P4: Low
    • 5.8.0
    • 4.7.2
    • Widgets: Layout
    • None
    • 8fbae648db3bc51bafacfe1f88e40561d357e60a

    Description

      I am using QFormLayout to dynamically create forms on the fly, many times per lifetime.

      To remove rows, I currently do

      while (QLayoutItem *item = ui->layout->takeAt(0)) {
              delete item->widget();
              delete item;
      }

      . I used to loop through the loop while(ui->layout->rowCount()), but it never ended. I then found out that rowCount() remains constant or grows, but never shrinks after takeAt(), just the rows become null.

      It seems that within qformlayout.cpp, d->m_matrix is never shrinked, only zeroed [0]. Within qformlayout.cpp, a class template FixedColumnMatrix is defined, which is the type of d->m_matrix. It only defines a single removal function "removeRow()". A simple textsearch for removeRow() shows that it is never called.

      I could of course try to patch, but then I am wondering why the original author did not do removes but zeroings, and my Qt wisdom is not deep enough to fully understand all interhappenings.

      While my program does not depend on the rowCount, I can't live with an ever growing qformlayout.cpp:QFormLayout::d->m_matrix.

      [0]:

      [...]
      QLayoutItem *QFormLayout::takeAt(int index) 
      {
          [...]
      
          QFormLayoutItem *item = d->m_matrix(row, col);
          Q_ASSERT(item);
          d->m_things.removeAt(index);
          d->m_matrix(row, col) = 0;
      
          invalidate();
      
          // grab ownership back from the QFormLayoutItem
          QLayoutItem *i = item->item;
          [...]
      }

      Attachments

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

        Activity

          People

            sgaist Samuel Gaist
            phresnel Sebastian Mach
            Votes:
            7 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes