开发者

GTK Scrolled Window - Keep Scroll Bar at bottom

开发者 https://www.devze.com 2022-12-27 11:01 出处:网络
I have a GTK/C++ program that uses a ScrolledWindow.I keep adding data to the list within the scrolled window, and I want to keep focus on the newest item.

I have a GTK/C++ program that uses a ScrolledWindow. I keep adding data to the list within the scrolled window, and I want to keep focus on the newest item. But I also want to allow the user to scroll through the data to select an old item. Is there a way to do this? I've looked everywhere but can't find anythi开发者_StackOverflow社区ng.


It's not quite clear to me what you mean by your question, but here's what I think you mean: when you add items to your list, they are added below the current visible portion of the list. So if you start out looking at the bottom of the list, then add a lot of items, you end up looking at the middle of the list. What you want is to scroll to the bottom of the list every time an item is added.

If that's correct, then just scroll the window to the bottom every time you add an item:

Gtk::Adjustment *adj = scrolled_window.get_vadjustment();
adj->set_value(adj->get_upper());
while(Gtk::Main::events_pending())
    Gtk::Main::iteration();


I had the same issue (developing on GTKmm)

as suggested by @ptomato

but the while loop should come up first before setting the value for vadjustment. (worked for me)

   while(Gtk::Main::events_pending())
         Gtk::Main::iteration();
   Gtk::Adjustment *adj =scrolled_window.get_vadjustment();
   adj->set_value(adj->get_upper());
0

精彩评论

暂无评论...
验证码 换一张
取 消