tags:

views:

59

answers:

4

Hi all,

I have a table with 3000 rows and 8 columns. I use the QTableView. To insert items I do:

QStandardItem* vSItem = new QStandardItem();
vSItem->setText("Blabla");
mModel->setItem(row, column, vSItem);

where mModel is QStandardItemModel. Everything is fine if I have not to many rows, but when I am trying to visualize big data (about 3000 rows), then it is extremely slow (20 seconds on Win 7 64-bit (8 core machine with 8 GB of RAM!!!)). Is there anything I can do to improve performance?

Thanks in advance.

A: 

Hey,

Do you have an autoresize on contents for your columns or rows ? It can be a killer in performance sometimes !

Have a look here : QHeaderView::ResizeToContents

Hope it helps !

Andy M
Not explicitly. Unless this is done per default, I don't have it.
Tom
What I have is: mUi.mImagesTableView->setAlternatingRowColors(true); mUi.mImagesTableView->setSelectionMode(QAbstractItemView::SingleSelection); mUi.mImagesTableView->setSelectionBehavior(QAbstractItemView::SelectRows); mUi.mImagesTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); mUi.mImagesTableView->setIconSize(QSize(vIconSize, vIconSize)); mUi.mImagesTableView->setColumnWidth(0, vIconPlusBorder); mUi.mImagesTableView->horizontalHeader()->setStretchLastSection(true);
Tom
try and disable the setStretchLastSection, disable the auto resize (I don't remember if it's done by default)... In other words try and disable everything that could be related to resize of rows and columns... In my application, in release, i have a treeview (with columns) with more than 10 thousand items and I can resize everything without problem... But if I switch on those auto-resize features, my perfs go down badly !
Andy M
note : Even in debug, you should have performance problem with that small amount of data...
Andy M
Random idea : Where do you create the datas ? In a method that is called lots of time ?
Andy M
I disabled it (setStretchLastSection), but it is still slow. Maybe there is something to disable that is enabled per default, but I do not know what. There is nothing with autoresize rows or columns in qtableview... And I am calling the method where I fill the data only once..
Tom
+1  A: 

I found a solution: the problem was that I assigned the model to the tableview already in the constructor. So everytime I inserted the item in the model, tableview was informed and probably updated. Now I assign the model to the tableview only after I filled my model with data. This is not an elegant solution but it works. Is there maybe a way to temporarily disable the model from tableview or something that says to the tableview to not to care about changes in the model?

Tom
You can try messing with blockSignals (http://doc.trolltech.com/main-snapshot/qobject.html#blockSignals) on the model, but that will probably cause you more headaches. Really, you should consider leaving the order the same, or changing to your own model (so you would know when to say you've changed data).
Caleb Huitt - cjhuitt
For large datasets, I would consider to write a "proper" model instead of using QStandardItemModel. There you can insert data in bigger chunks than single items, each triggering the view to update, which should me vastly more performant. Edit: I see I just repeated what James said below...
Frank
A: 

For this quantity of data, you'd be better with a custom model - then you'd have the control of when you inform the view of updates, for example. The 'standard' items scale to hundreds, and probably thousands, due to modern hardware being fast, but they're explicitly documented as not being intended for datasets of this size.

James Turner
A: 

Also, if all your rows have the same height, setting http://doc.qt.nokia.com/4.7/qtreeview.html#uniformRowHeights-prop to true can boost performance. In my case, a model containing about 50.000 rows was almost unusable with uniformRowHeights set to false (the default). After changing it to true, it worked like a charm.

bjoern.bauer