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

QListView::setRowHidden() is very slow when hiding large numbers of items

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • 4.8.0
    • 4.6.3, 5.6.1
    • Widgets: Itemviews
    • None
    • 4be622995ad6a46b10788f5d62ed2368cffcb3dd, 7907fc2c3 (master)

    Description

      When hiding a large number of items (more than 20000) in QListView using QListView::setRowHidden(), then it is very slow compared to other views. (e.g. QTreeView). It seems that adding items to "QVector<QPersistentModelIndex> hiddenRows" takes time.

      The following example demonstrates the problem:

      #include <QtGui>
      
      QList<QModelIndex>myList;
      class ListView : public QListView
      {
      	Q_OBJECT
      public:
      	ListView()
      	{
      		QStringListModel *myModel = new QStringListModel(this);
      		QStringList list;
      		for (int i = 0; i < 50000; i++) {
      			list << QString::number(i);
      		}
      		
      		myModel->setStringList(list);
      		setModel(myModel);
      		QTimer::singleShot(3000, this, SLOT(test1()));
      	}
      	public slots:
      		void test1()
      		{
      			setUpdatesEnabled(false);
      			QTime t;
      			t.start();
      			for (int i = 0; i < 30000; i++) {
      			setRowHidden(i, true);
      			}
      			qDebug() << t.elapsed();
      			setUpdatesEnabled(true);
      			
      
      		}
      private:
      	QSortFilterProxyModel *myProxy;
      		
      };
      
      class TreeView : public QTreeView
      {
      	Q_OBJECT
      public:
      	TreeView()
      	{
      		QStringListModel *myModel = new QStringListModel(this);
      		QStringList list;
      		for (int i = 0; i < 50000; i++) {
      			list << QString::number(i);
      		}
      		
      		myModel->setStringList(list);
      		setModel(myModel);
      		QTimer::singleShot(3000, this, SLOT(test1()));
      	}
      	public slots:
      		void test1()
      		{
      			setUpdatesEnabled(false);
      			QTime t;
      			t.start();
      			for (int i = 0; i < 30000; i++) {
      			setRowHidden(i, QModelIndex(), true);
      			}
      			qDebug() << t.elapsed();
      			setUpdatesEnabled(true);
      			
      
      		}
      		
      };
      
      #include "main.moc"
      
      int main(int argc, char** argv)
      {
      	QApplication app(argc, argv);
      #if 1
      	ListView window;
      #else
      	TreeView window;
      #endif
      	window.resize(100, 50);
      	window.show();
      	return app.exec();
      
      }

      Attachments

        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
            naevdal Sigrid Fjell Nævdal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes