The list widget only paints items that are visible in the view anyway.
You must be doing something odd because I can add 500 simple items to a list widget in around a millisecond. The list widget is fully displayed while the items are being added, and scrolls smoothly top to bottom. Even on a much slower machine I cannot see it taking 5000 milliseconds for 200.
#include <QtGui>
#include <QDebug>
Q_OBJECT
public:
QTimer::singleShot(0,
this,
SLOT(fill
()));
}
public slots:
void fill() {
qDebug() << __func__;
t.start();
for (int i = 0; i < 500; ++i) {
addItem(item);
}
qDebug() << "Elapsed time:" << t.elapsed() << "ms";
}
};
int main(int argc, char *argv[])
{
MyListWidget w;
w.show();
return app.exec();
}
#include "main.moc"
#include <QtGui>
#include <QDebug>
class MyListWidget: public QListWidget {
Q_OBJECT
public:
MyListWidget(QWidget *p = 0): QListWidget(p) {
QTimer::singleShot(0, this, SLOT(fill()));
}
public slots:
void fill() {
QTime t;
qDebug() << __func__;
t.start();
for (int i = 0; i < 500; ++i) {
QListWidgetItem *item = new QListWidgetItem(QString("Item %1").arg(i));
addItem(item);
}
qDebug() << "Elapsed time:" << t.elapsed() << "ms";
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyListWidget w;
w.show();
return app.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
output:
fill
Elapsed time: 1 ms
fill
Elapsed time: 1 ms
To copy to clipboard, switch view to plain text mode
What are you doing while loading the data into the list widget that is taking so long?
Bookmarks