Solved Header from tableview doesnt update after sorting
-
Hi.
When i sort my tableview the header doesnt update until i hover wiht the mouse over each header cell. Why? -
Hi,
Are you using a custom model ?
-
Indeed i do. Im doing the sorting trough resetting the model data.
-
Reset the model ?
Are you also re-implementing the headerData method ?
-
Yes, with emit beginresetmodel and endresetmodel. I need my model updated every second.
Yes, like this
if (role != Qt::DisplayRole) return QVariant(); if ( orientation == Qt::Vertical ) { ... return bla; } if(orientation == Qt::Horizontal) { if(section == 0) { return blabla1 } if(section == 1) { return blabla2 } } return QVariant();
-
@Maser
instead of resetting the whole model (when it's not necessary) you should only emit the changed signals of the data which has actually changed. And let Qt do the optimization.So emit headerDataChanged() instead.
-
It is necessary because i need the view updated every second, and yes, all data changes every second cause it is calculated data i receive from the model, bound on current time.
But thanks, emmiting headerdatachanged helped. -
Even if all the data is changed, you can emit a dataChanged for the whole model.
resetModel is usually used when the model layout changes, which doesn't seems to be your case.
-
@Maser
to add up to @SGaist
a model reset is more radical approach of telling the view that the data has changed.
A model reset implies that the selection and current gets lost, the current scroll position is reset, ...
So you should only reset (also from the user experience point of view) when the structure of the model changes. But as long as just the "content" of existing items change you should emit the dataChanged() signal instead. -
My bad. I use dataChanged, like SGaist hinted in another thread. Was just a bit confused in my own code))
But dataChanged doesnt update header when the table is sorted, while headerDataChanged does.