无法滚动到 TreeView PyGTK / GTK 的末尾
当我尝试向下滚动到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
经过这么多年,
scroll_to_cell()
和set_cursor()
在某些情况下似乎仍然不准确。一种解决方法是使用get_vadjustment()
/get_hadjustment()
获取TreeView
小部件的Adjustment
(来自Scrollable
接口)并计算我们自己需要的值。如果我们想垂直滚动到给定路径的行:
scroll_to_cell()
andset_cursor()
still seem to be inaccurate in some cases after all these years. One workaround would be to get theAdjustment
's of ourTreeView
widget withget_vadjustment()
/get_hadjustment()
(from theScrollable
interface) and calculate the values we need ourselves.If we want to scroll vertically to a row with given path: