View Full Version : Jump to a cell in QTableView

29th June 2012, 22:16
Hello all,

I'm basically making a spreadsheet, and I'm currently implementing a 'find' feature.

Two questions

1) Once I found the cell with the request content, how do I force the QTableView to 'jump' to that cell? By 'jump', I mean QTableView by itself moves to that cell and shows it(it might pages and pages of cells).

2) Secondly, I feed a QAbstractTableModel to a QSortFilterProxyModel and the proxy is used for the model for the QTableView. If I were to find a cell with a given text and save it for future use(like "Find Next" begins searching from last occurence), and then the view changed, would that cell information(say row and col) be now invalid? It appears to be the case, so how would I go about implementing a 'find next' feature that can handle this type of logic?


30th June 2012, 07:07
1) QAbstractItemView::scrollTo()

2) Sorting or filtering in the view will invalidate QModelIndexes (or leave them pointing in the wrong place). Doing these things, especially sorting, will also invalidate the idea of the 'next' match anyway. You could store a QPersistentModelIndex which should only become invalid if the cell is actually removed, or retrieve some other unique identifier for the cell from the underlying model and find the cell using that when next required.