我正在开发一个GTK应用程序(在Python中使用PyGTK),我需要手动将Gtk.ScrolledWindow滚动到它包含的一个孩子,以便在屏幕上显示它。
ScrolledWindow包含一个ListBox,其中包含大量的ListBoxRow。
self.currencySwitcher = CurrencySwitcher(self) self.currencySwitcherBox = Gtk.ScrolledWindow(vexpand = True) self.currencySwitcherBox.add(self.currencySwitcher)
Gtk.ListBox的CurrencySwitcher herits:
class CurrencySwitcher (Gtk.ListBox): # ...
我有一个搜索系统来查找此ListBox中的特定行,但是当我通过搜索行单击时,它在屏幕上是不可见的(我必须滚动才能看到它),因此我必须能够滚动到孩子以在屏幕上看到它,而不必手动滚动ScrolledWindow
我该怎么做呢?我已经搜索了很多,但我找不到一个好的答案。谢谢
发布于 2019-03-07 22:47:29
Gtk.ListBox也继承自Gtk::Container,所以看看Gtk.Container的set_focus_vadjustment()和set_focus_hadjustment()成员。
一旦您在ListBox上调用了这两个函数中的一个或两个,您就可以拥有您的ListBoxRow子grab_focus() (继承自Gtk.Widget),它将滚动到视图中。
https://stackoverflow.com/questions/54007196
复制相似问题