Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
4.6.3, 5.6.1
-
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(); }