Manually scroll to a child in a Gtk.ScrolledWindow

隐身守侯 提交于 2020-07-22 06:07:51

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/54007196/manually-scroll-to-a-child-in-a-gtk-scrolledwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!