I have a QTableView with a QAbstractTableModel child instance set as the model. The child implements void sort(int columnt, Qt::SortOrder order). I set QTableView::sortEnabled(bool) to true so I can sort my table by clicking on the column header. When I click the header sorting finishes almost instantly but the table is only updated when I move the mouse to the table area. Do I need to emit some signal from sort()? Or call a function to update the QTableView?

有帮助吗?

解决方案

A bit tricky: do emit dataChanged( QModelIndex(), QModelIndex() ); after sorting.

I want to note, that passing invalid indexes is not documented, but I often use it in my projects. It works well and it's much faster than passing valid indexes with big ranges, because cause to update only visible area. But it may have some glitches with heavy delegates / custom widgets.

I tested on QTreeView - updating range of 10k elements takes about 1,5 sec (emitting dataChanged with valid indexes). And when I use invalid indexes signal is processed immideatly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top