How to scroll to last row of a Sqlite model in a QTableView?
QSqlTableModel
loads data lazily, i.e. it will load the items when it's asked for. And QTableView
will ask for items if it needs to display them. That delay you observe is the part that QSqlTableModel
fetches new data from the database.
There is also an issue, if SQL drivers doesn't report Query size, and SQLite is one of them:
If the database doesn't return the number of selected rows in a query, the model will fetch rows incrementally. See fetchMore() for more information.
So the model actually doesn't know how many items there will be until it loads all the items.
In order to eliminate the delay you should load all data beforehand (as fetchMore
suggests):
self.db = QtSql.QSqlDatabase.addDatabase("QSQLITE")self.db.setDatabaseName(dbFileName)self.model = QtSql.QSqlTableModel(self.db)self.model.setTable("results")self.model.select()while self.model.canFetchMore(): self.model.fetchMore()self.tableViewResults.setModel(self.model)