Search code examples
gtkpygtkgtkscrolledwindow

Manually scroll to a child in a Gtk.ScrolledWindow


I'm developping a GTK app (in Python with PyGTK) and I need to scroll manually the Gtk.ScrolledWindow to a child it contains to show it in the screen.

The ScrolledWindow contains a ListBox, which contains a lot of ListBoxRow.

self.currencySwitcher = CurrencySwitcher(self) self.currencySwitcherBox = Gtk.ScrolledWindow(vexpand = True) self.currencySwitcherBox.add(self.currencySwitcher)

CurrencySwitcher herits of Gtk.ListBox:

class CurrencySwitcher (Gtk.ListBox): # ...

I have a search system to find a specific row in this ListBox, but when I click by searching on a row, it is not visible on the screen (I must scroll to see it) So I must be able to scroll to a child to see it on the screen without have to manually scroll the ScrolledWindow

How can I do this ? I have already search a lot but i can't found a good answer. Thanks


Solution

  • Gtk.ListBox also inherits from Gtk::Container, so have a look at the set_focus_vadjustment() and set_focus_hadjustment() members of Gtk.Container.

    Once you have called one or both of these functions on your ListBox, you can have your ListBoxRow child grab_focus() (inherited from Gtk.Widget) and it will be scrolled into view.