手动滚动到Gtk.ScrolledWindow中的子级 [英] Manually scroll to a child in a Gtk.ScrolledWindow

查看:71
本文介绍了手动滚动到Gtk.ScrolledWindow中的子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发GTK应用程序(在带有PyGTK的Python中),我需要手动滚动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.

ScrolledWindow包含一个ListBox,其中包含很多ListBoxRow.

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

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

Gtk.ListBox的CurrencySwitcher继承程序:

CurrencySwitcher herits of Gtk.ListBox:

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

我有一个搜索系统,可以在此列表框中找到特定的行,但是当我通过搜索某一行单击时,它在屏幕上不可见(我必须滚动才能看到它)因此,我必须能够滚动到一个孩子才能在屏幕上看到它,而不必手动滚动ScrolledWindow

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

推荐答案

Gtk.ListBox 也继承自 Gtk :: Container ,因此请查看 Gtk.Container 的> set_focus_vadjustment()和 set_focus_hadjustment()成员.

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

一旦在ListBox上调用了这两个功能之一或全部,就可以让ListBoxRow子元素 grab_focus()(从Gtk.Widget继承),它将滚动到视图中.

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.

这篇关于手动滚动到Gtk.ScrolledWindow中的子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆