Gtk,如何滚动视口列表的底部? [英] Gtk, How to scroll at bottom of viewport list?

查看:116
本文介绍了Gtk,如何滚动视口列表的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GtkVBox和GtkViewPort创建了一个列表。
我正在做两个上/下GtkButton的滚动。

I have created one list with GtkVBox and GtkViewPort.
and i am doing the scroll by two up/down GtkButtons.

    GtkAdjustment* adjustment;
    adjustment = gtk_viewport_get_vadjustment(GTK_VIEWPORT(viewport_ptr));
    gtk_adjustment_set_value(adjustment, gtk_adjustment_get_value(adjustment)+(gdouble)SCROLL_SIZE);
    gtk_widget_show_all(viewport_ptr);

但是,当我将小部件添加到VBox时,它会在VBox的最后添加,因为我正在使用 gtk_box_pack_start 。所以我想滚动视口到这个新添加的最后一个小部件,它位于列表的最底部。

But when I add the widget to VBox it gets added at the end of the VBox as I am using gtk_box_pack_start. So i want to scroll viewport up to this newly added last widget which is at bottom of the list.

推荐答案

将调整设置为最大值:

Did you try just setting the adjustment to the maximum value:

gtk_adjustment_set_value(adjustment, gtk_adjustment_get_upper(adjustment));

请注意,您可能需要延迟此操作,或者从适当的事件触发它,因为上限会随着滚动的vbox的增长而改变。

Note that you might need to delay this, or trigger it from a suitable event, since the upper bound will change as the scrolled vbox grows.

我的建议是将它挂到 size-allocate 信号。

My suggestion would be to hook it into the size-allocate signal of the GtkVBox.

这篇关于Gtk,如何滚动视口列表的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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