RE: Scrolling TextView, how can I make the vert scrollbar keep up ?



I've made a GtkTextView widget with both a vertical and a horizontal
scrollbar. When the TextView gets flooded with data (far more than the
widget can display), I'd like the vertical scrollbar to autoscroll to
always show the most recent data. Kind of like a term window.

What is the magic attribute that needs to be set for this to 
happen? I'm
using Glade for the UI if that means anything.

Unfortunately, you can not do it with glade.  You have to do it manually in
code.

This should do the trick:

        GtkTextBuffer *buffer = NULL;
        GtkTextMark *mark = NULL;

        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(mytextview));

      mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE);
      gtk_text_view_scroll_mark_onscreen(mytextview, mark);
      gtk_text_buffer_delete_mark(buffer, mark);

Where &iter is the location you want to scroll to.  You can make this the
top most or bottom most location by using the start iter or the end iter:


        GtkTextIter iter_start, iter_end;

        gtk_text_buffer_get_bounds(buffer, &iter_start, &iter_end);

Regards,
Martyn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]