There is no default autoscrolling feature, but you can get the behavior relatively simple. Your model will emit rowsInserted
when you insert/append rows. You can connect to that signal and call scrollToBottom
on your view.
There is one problem though. View needs to adjust itself, because it won't put the item at the bottom immediately when rowsInserted
fires. Calling scrollToBottom
within a QTimer.singleShot
solves this because QTimer
will wait until there are no pending events (like update of the view).
Assuming the model is stored as self.model
and view is self.view
, this is how it'll look:
self.model.rowsInserted.connect(self.autoScroll)
and the autoScroll
method:
def autoScroll(self):
QtCore.QTimer.singleShot(0, self.view.scrollToBottom)
Or if you prefer not having a seperate method for this:
self.model.rowsInserted.connect(lambda: QtCore.QTimer.singleShot(0, self.view.scrollToBottom))