I have an application that will add a Widget
to an HBox
, which is contained i开发者_Go百科n a ScrolledWindow
. When a Widget
is added, I would like the parent ScrolledWindow
to scroll to the right, where the newly added Widget
is. Adding the widget works just fine, my problem is:
How can I make the ScrolledWindow move when a child is added?
My Vala code looks something like:
private void addView() {
var widget = this.createWidget();
this.box.pack_start(widget); // this.box is a HBox
widget.show_all();
var adj = this.parent_win.get_hadjustment(); // parent_win is a ScrolledWindow
adj.set_value(adj.get_upper());
}
The behavior I am getting now is the adjustment will work every other double click (what signals all this). I would like for the adjustment to occur on every double click.
update I have seen this: Gtk, How to scroll at bottom of viewport list? , but there is no real definitive answer given. you mean to tell me i have to set a 1 sec timeout to scroll ?
Use an idle callback instead of a timeout, and use the GtkContainer::add signal to get notified when a new child is added (http://developer.gnome.org/gtk/unstable/GtkContainer.html#GtkContainer-add).
精彩评论