PDA

View Full Version : QTableView



br73
12th February 2009, 17:39
I'm using QTableView with a QAbstractTableModel. I'm updating my QAbstractTableModel quite frequently from an outside source (not the QTableView). The updates to the table model only occur on a single row and when complete I send the dataChanged signal with a begin index and end index indicating that just the row is updated. The code basically looks like the following:

int row = 5;
int columnCount = 10;

QModelIndex begin = index(row, 0);
QModelIndex end = index(row, columnCount);
emit dataChanged(begin, end);

For some reason whenever I emit this signal the TableView calls my TableModel's data method for every visible row. I believe this is causing a considerable hit to performance. Is this the usual behavior for this situation or is there a way to have the TableView only request updates for the index range that was sent in the dataChanged signal.

Thanks,
Bryan

faldzip
12th February 2009, 18:22
As it stand in docs, both begin and end index are included to the bunch of indices for update. But there's no such index like index(row, columnCount) because last column index is columnCount-1 so it should be:


QModelIndex begin = index(row, 0);
QModelIndex end = index(row, columnCount - 1);
emit dataChanged(begin, end);


Read docs carefully.

br73
12th February 2009, 21:17
Thanks for the response. Tried this out, but QTableView seems to still insist on calling data function for all visible rows, not just the one updated.

montylee
13th February 2009, 01:40
To update only 1 row, try calling dataChanged with same arguments i.e.
emit dataChanged(begin, begin)

i.e. try calling dataChanged for each column of the same row separately.

br73
16th February 2009, 20:32
Thanks Monty. Works great.