Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QTableView is extremely slow (even for only 3000 rows)

Tags:

qt

qtableview

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.

like image 695
Tom Avatar asked Oct 27 '10 08:10

Tom


3 Answers

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 !

like image 67
Andy M Avatar answered Oct 13 '22 22:10

Andy M


Good call on the autoresize on contents for your columns or rows.

I have a function that added a column to the table each time a client connected to my server application. As the number of columns in the table got large, the insertion time seemed to take longer and longer.

I was doing a ui->messageLog->resizeRowsToContents(); each time. I changed this to only auto resize the row that was being added ui->messageLog->resizeRowToContents(0);, and the slowness went away.

like image 8
Eric Avatar answered Oct 13 '22 23:10

Eric


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?

like image 3
Tom Avatar answered Oct 13 '22 21:10

Tom