无法滚动到 TreeView PyGTK / GTK 的末尾

发布于 2024-09-15 05:29:09 字数 576 浏览 6 评论 0原文

当我尝试向下滚动到 TreeView 的末尾(位于 ScrolledWindow 内)时,它不会滚动到应该滚动的位置,而是滚动到前面的一两行。

我尝试了几种方法,它们都提供相同的行为:

self.wTree.get_widget("tree_last_log").scroll_to_cell((self.number_results-1,))
# or 
self.wTree.get_widget("tree_last_log").set_cursor((self.number_results-1,))
# or 
adj = self.wTree.get_widget("scrolledwindow1").get_vadjustment()
adj.set_value(adj.get_property('upper'))
self.wTree.get_widget("scrolledwindow1").set_vadjustment(adj)
# or 
self.wTree.get_widget("scrolledwindow1").emit('scroll-child', gtk.SCROLL_END, False)

问题出在哪里?

When I try to scroll down to the end of my TreeView, which is inside a ScrolledWindow, it doesn't scroll where it should but one or two lines before.

I tried several methods and they all provide the same behavior :

self.wTree.get_widget("tree_last_log").scroll_to_cell((self.number_results-1,))
# or 
self.wTree.get_widget("tree_last_log").set_cursor((self.number_results-1,))
# or 
adj = self.wTree.get_widget("scrolledwindow1").get_vadjustment()
adj.set_value(adj.get_property('upper'))
self.wTree.get_widget("scrolledwindow1").set_vadjustment(adj)
# or 
self.wTree.get_widget("scrolledwindow1").emit('scroll-child', gtk.SCROLL_END, False)

Where is the problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅语花开 2024-09-22 05:29:09

C API 文档可能会有所帮助:
http://library.gnome .org/devel/gtk/stable/GtkTreeView.html#gtk-tree-view-scroll-to-cell

你可以看到那里有一些参数会搞乱事情,具体取决于 pygtk 如何默认它们。您可以尝试显式指定所有参数。

TreeView 和 TextView 的一个技巧是它们进行异步布局,因此如果尚未计算行高,则调整的“上部”很可能为零。

如果调整不当,则无需将其调回原位,尽管这应该是无害的。

'scroll-child' 信号不是你想要的,这是一个用于绑定按键的按键绑定信号。

The C API docs may be helpful:
http://library.gnome.org/devel/gtk/stable/GtkTreeView.html#gtk-tree-view-scroll-to-cell

You can see there are arguments there that would mess things up, depending on how pygtk defaults them. You might try specifying explicitly all the args.

One trick to TreeView and TextView is that they do asynchronous layout so the "upper" on the adjustment may well just be zero if row heights haven't been computed yet.

if messing with the adjustment, there's no need to set it back, though it should be harmless.

'scroll-child' signal is not what you want, that's a keybinding signal used to bind keys to.

优雅的叶子 2024-09-22 05:29:09

经过这么多年,scroll_to_cell()set_cursor() 在某些情况下似乎仍然不准确。一种解决方法是使用 get_vadjustment() / get_hadjustment() 获取 TreeView 小部件的 Adjustment (来自 Scrollable 接口)并计算我们自己需要的值。

如果我们想垂直滚动到给定路径的行:

    bg_area = treeview.get_background_area(path, None)
    vis_rect = treeview.get_visible_rect()
    v_adj = treeview.get_vadjustment()
    v_adj.set_value(bg_area.y + vis_rect.y)

scroll_to_cell() and set_cursor() still seem to be inaccurate in some cases after all these years. One workaround would be to get the Adjustment's of our TreeView widget with get_vadjustment() / get_hadjustment() (from the Scrollable interface) and calculate the values we need ourselves.

If we want to scroll vertically to a row with given path:

    bg_area = treeview.get_background_area(path, None)
    vis_rect = treeview.get_visible_rect()
    v_adj = treeview.get_vadjustment()
    v_adj.set_value(bg_area.y + vis_rect.y)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文