GTK滚动窗口 - 将滚动条保持在底部 [英] GTK Scolled Window - Keep Scroll Bar at bottom

查看:357
本文介绍了GTK滚动窗口 - 将滚动条保持在底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ScrolledWindow的GTK / C ++程序。我一直向滚动窗口中的列表添加数据,并且我想关注最新的项目。
但我也想允许用户滚动浏览数据来选择一个旧的项目。
有没有办法做到这一点?我找遍了,但找不到任何东西。

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 anything.

推荐答案

我不清楚你的问题是什么意思,但这是我认为你的意思:当你添加项目到你的列表中时,它们被添加到列表的当前可见部分的下面。因此,如果您开始查看列表底部,然后添加大量项目,则最终会查看列表中间的内容。你想要的是每次添加项目时滚动到列表的底部。

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

这篇关于GTK滚动窗口 - 将滚动条保持在底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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