tags:

views:

88

answers:

1

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);

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.

+1  A: 

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

gtk_adjustment_set_value(adjustment, gtk_adjustment_get_upper(adjustment));

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.

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

unwind
It worked, it scrolls till end of VBox and i am doing this in map event of View Port. But problem is that when i add Widgets to VBox and do the same it does not scroll to last widget it scrolls upto 2nd last widget. What do i missing?
PP
@PP: You're probably doing the scrolling too soon, before the scrolling area has understood that its child (the vbox) has grown, and updated the upper limit of its vertical adjustment.
unwind
I am doing it after adding widgets to VBox and `gtk_widget_show` on view port. Where should i do it.do i need to put delay or something or one some events?
PP