View Full Version : QTableWidget performance issues when setting column spans

9th February 2009, 20:57
I'm currently using Qt 4.5.0, but Qt 4.4.3 had the same problem.

The problem happens when you have a large QTableWidget table (of about 12,000 rows in my case) and you increase the column span of at least some of its rows. Then, whenever you try to select all of the cells in the table (by pressing Ctrl+A) or whenever you try to select only 1 column by clicking on the column header with the mouse, the table will slow down to a crawl and you won't be able to do anything else for a long time. I never experienced this problem using Qt3, with tables as large as this one.

Here is some code that shows this problem:

#include <QtGui/QtGui>

int main (int argc, char *argv[])
QApplication app(argc, argv);
const int ROWS = 12000;
const int COLS = 15;
const int ROWSPAN = 1;
const int FIRSTCOL = 0;

QTableWidget table(ROWS, COLS);
for (int i=0; i<ROWS; i++) {
for (int j=0; j<COLS; j++)
table.setItem(i, j, new QTableWidgetItem("Test123"));

//Set a comment row every 10 rows. This causes performance problems.
if (i%10 == 0)
table.setSpan(i, FIRSTCOL, ROWSPAN, COLS);

return app.exec();