c++ - QTableView preserve selection after model refresh -


i tried build user interface displays content of table while data refreshed every second.

therefore have chain of models:

  • qsqltablemodel - access tables content
  • mymodel - inherited qidentityproxymodel modify data bit (source tablemodel)
  • somefiltermodels - have mymodel source

this chain ends in qtableview. because qsqltablemodel refreshed every second, selection in tableview removed every second also. had 2 ideas fix this.

  1. prevent tablemodel detecting changes. not working well.
  2. catching events fired before , after model change store , restore current selection. sadly qidentityproxymodel not forward signals modelabouttobereset or modelreset or datachanged .. impossible reemit signals mymodel because private.

i searching other ways counter refresh problems without success. can't imagine first person uses chain of proxy models combined periodic model refresh , selections.

can give me tips?

thanks in advance.

maybe worth note:

  • one qsqltablemodel used many tableviews. (with different filterproxymodel chain.) can't stop refreshing because 1 view has selection.
  • you may think know when call models refresh method. bit complicated pass trough ui architecture. mean model updated , tableview has connection updated model through proxymodels. there should no need way of communication.

hope question makes sense.

qabstractitemmodel includes number of signals can know when data in model or changing. in particular, has following signals:

  • datachanged
  • headerdatachanged
  • modelabouttobereset
  • modelreset
  • columnsabouttobeinserted
  • columnsabouttobemoved
  • columnsabouttoberemoved
  • columnsinserted
  • columnsmoved
  • columnsremoved
  • rowsabouttobeinserted
  • rowsabouttobemoved
  • rowsabouttoberemoved
  • rowsinserted
  • rowsmoved
  • rowsremoved

given lose selection, assume bolded signals ones want concerned with, because default qt behavior preserve selection if can columns or rows removed/inserted , doesn't affect selection.

once connected these signals, in modelabouttobereset suggest getting ids cells can reuse select them again, , in modelreset using ids qmodelindexs , using them again select same cells.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -