GTK滚动窗口-滚动条位于底部 [英] GTK Scrolled Window - Keep Scroll Bar at bottom

查看:226
本文介绍了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天全站免登陆