I just did this. First, you have to connect the header signal to the sort method you have created. This is a Python sample so you'll need to adapt it to C++:
model = SBStateTableModel()
table = QtGui.QTableView()
table.setModel(model)
table.setSortingEnabled(True)
When you sort, the entire view will change - or at least most of the view will change. So emitting the modelReset
signal will cause the view to change. Model reset is one of the most inefficient signals to call, because it causes the entire view to be redrawn. However, most of the view will change anyway on a sort.
emit modelReset();
You could also emit the dataChanged
signal, indicating that all of the data has changed. The dataChanged
signal may be faster.
Python:
self.dataChanged.emit(self.index(0, 0), self.index(self.rowCount()-1, self.columnCount()-1))
C++:
(emitting a dataChanged signal, in a subclass of QTableView)
auto m = model();
emit dataChanged (m->index(0, 0), m->index(m->rowCount()-1, m->columnCount()-1));