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

ListView (and TableView) behaves badly for very large models

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3: Somewhat important
    • None
    • 6.8.0 RC
    • None
    • Ubuntu 22.04, Android
    • Android, Linux/Wayland

    Description

      The delegate positions seems to be incorrect if a large model (millions of rows) is used with a ListView (or a TableView). The first ~3.3 million items looks fine, but then spacing gets more and more distorted.

      Qml:

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Layouts
      import model1
      ApplicationWindow {
          visible: true
          
          ListView {
              id: listView
              anchors.fill: parent
              model: model1
              
              ScrollBar.vertical: ScrollBar {
                  policy: ScrollBar.AlwaysOn
              }
              
              delegate: Rectangle {
                  width: listView.width
                  height: 20
                  Text {
                      text: display
                      anchors.centerIn: parent
                  }
              }
          }
      }

      Model:

      #include <QAbstractListModel>
      class Model1 : public QAbstractListModel 
      {
          Q_OBJECT
      public:
          
          Model1(QObject* parent = nullptr): QAbstractListModel(parent) 
          {
          }
          
          int rowCount(const QModelIndex& parent = QModelIndex()) const override 
          {
              return 20000000;
          }
          
          QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override 
          {
              if (role == Qt::DisplayRole)
                  return index.row();
      
              return QVariant();
          }
      };

      Main:

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QQmlContext>
      #include "model1.h"
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
          QQmlApplicationEngine engine;
          Model1 model;
          engine.rootContext()->setContextProperty("model1", &model);
          engine.loadFromModule("model1", "Main");
          
          return app.exec();
      }
       
      

       

      Attachments

        1. 3.png
          17 kB
          Henrik Eriksson
        2. 2.png
          11 kB
          Henrik Eriksson
        3. 1.png
          7 kB
          Henrik Eriksson

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              heneri Henrik Eriksson
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes