PyGObject Scroll to bottom of ScrolledWindow() after adding row to child TreeView

34 Views Asked by At

I am building a GUI program that features a "history" that consists of an expanding list containing text entries for every action. I display this using a TreeView whose model is updated every time the history updates. This part works.

I want the history list to scroll to the bottom to display the most recently added entry every time an entry is added. This is the current code:

def update_history(self, command):
    self.history.append([command])  # self.history is the ListStore model

    self.history_list.show_all()    # self.history_list is the TreeView object

    adj = self.scrollbox.get_vadjustment()
    adj.set_value(adj.get_property('upper'))
    self.scrollbox.set_vadjustment(adj) # self.history_list is a child of self.scrollbox

The issue is that this code scrolls the window to the bottom, and THEN the treeview renders the new entry, and thus we aren't actually scrolled to the bottom but to the entry just before.

This is almost a duplicate of Can't scroll to the end of TreeView PyGTK / GTK, however that thread is 12 years old and has succumbed to linkrot.

Gtk Version: 3.24.34 PyGObject Version: 3.42.2

0

There are 0 best solutions below