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

ListView displays weird spaces when adding elements in delegate's onCompleted callback

    XMLWordPrintable

Details

    • e8570bd1af74724b6fae1ac8a2d8bbdfee7a6504

    Description

      I created a simple example that uses a TreeModel and a TreeView.
      The item delegate of the TreeView is expanded automatically in the Component.onCompleted signal handler.
      The model is based on the example at http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html. The only modifications to the model are in the setup function and in the columnCount function.
      The issue is the visualization of weird spaces between the items of the treeview.

      See the attached screenshot and sample project for reproducing the bug


      However, this has actually nothing to do with TreeView or AbstractItemModel. A plain ListView with a QML ListModel does the same thing:

      import QtQuick 2.9
      import QtQuick.Window 2.2
      
      Window {
          width: 640
          height: 480
          visible: true
      
          ListModel {
              id: listModel
              ListElement { name: "a" }
              ListElement { name: "b" }
              ListElement { name: "c" }
              ListElement { name: "d" }
              ListElement { name: "e" }
              ListElement { name: "f" }
              ListElement { name: "g" }
              ListElement { name: "h" }
              ListElement { name: "i" }
              ListElement { name: "j" }
          }
      
          ListView {
              id: treeView
              anchors.fill: parent
              model: listModel
      
              delegate: Text {
                  text: name
                  Component.onCompleted: {
                      console.log(index, name);
                      if (name.length === 1) {
                          for (var i = 0; i < 10; ++i)
                              listModel.insert(index + 1, {name: name + i});
                      }
                  }
              }
          }
      }
      

      Mind that the ListModel example is less deterministic, though. Sometimes the gap appears after "b", sometimes after "c" and sometimes not at all.

      Attachments

        1. TreeViewDisplayBug.zip
          7 kB
        2. Untitled.png
          Untitled.png
          16 kB
        3. Untitled.png
          Untitled.png
          16 kB
        4. Untitled.png
          Untitled.png
          16 kB
        5. Untitled.png
          Untitled.png
          16 kB

        Issue Links

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

          Activity

            People

              ulherman Ulf Hermann
              cuke Filippo Cucchetto
              Votes:
              24 Vote for this issue
              Watchers:
              32 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes