I tried to build a user interface which displays the content of a table while the data is refreshed every second.
Therefore I have a chain of models:
QSqlTableModel
- to access the tables content- MyModel - inherited from
QIdentityProxyModel
to modify the data a bit (source is the TableModel) - SomeFilterModels - which have MyModel as source
This chain ends in a QTableView
. Because the QSqlTableModel
is refreshed every second,
any selection in the TableView is removed every second also. Now I had two Ideas to fix this.
- Prevent the TableModel from detecting changes. Which was not working very well.
- Catching some events fired before and after the model is about to change to store and restore the current selection. Sadly the
QIdentityProxyModel
does not forward signals like modelAboutToBeReset or modelReset or dataChanged .. it is also impossible to reemit those signals from MyModel because they are private.
I was searching for other ways to counter those refresh problems without success. But I can't imagine that I am the first person who uses a chain of proxy models combined with a periodic model refresh and selections.
Can anyone give me some tips?
Thanks in advance.
Maybe worth to note:
- One
QSqlTableModel
is used for many TableViews. (With a different FilterProxyModel chain.) So I can't just stop refreshing because one View has a selection. - You may think that I know when I call the models refresh method. But for now it is a bit to complicated to pass this trough my ui architecture. I mean the model is updated and the TableView has already a connection to the updated model through some ProxyModels. There should be no need for another way of communication.
Hope my question makes sense.