刷新 GTK 中显示的文本+小部件?

发布于 2024-08-29 06:26:23 字数 189 浏览 2 评论 0原文

由于对使用 GTK+ 相当陌生,我并不完全了解它的所有功能。

基本上,我有一个有 4 列的 GtkTreeView 小部件。我需要每隔几秒更新 4 列中显示的文本,但我不知道如何在 GTK+ 中执行此操作。

我知道我可以使用 gtk_tree_store_clear 刷新数据,但我不确定如何重新填充列并刷新顶级窗口以显示此新数据?

Being resonably new to using GTK+, im not fully aware of all its functionality.

Basically, I have a GtkTreeView widget that has 4 Columns. I need to update the text displayed in the 4 columns every couple of seconds, but im not aware how to do this in GTK+.

I'm aware that I could flush the data using gtk_tree_store_clear, but I'm not sure how to repopulate the columns and have the top level window refresh to show this new data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-09-05 06:26:23

您需要将 GtkTreeIter 获取到正确的行,然后使用适当的(特定于模型的)setter 来更改数据。

例如 gtk_list_store_set() 用于 GtkListStore 模型。

如果只想更改部分数据,则无需清除整个模型,这是非常浪费且缓慢的。

如果您确实需要更改所有数据,那么当然要清除它。

您不必担心显示刷新;视图侦听来自模型的事件,并在模型更改时自动知道刷新。

更新:

更改数据时(如评论中所述),您不需要“刷新”旧数据。该模型拥有数据,并且知道如何跟踪所使用的内存。您只需根据需要使用上述 gtk_list_store_set() 调用即可将新的所需数据放入模型中。您可以根据需要经常执行此操作,并且每几秒一次的更新频率应该没有问题。

当然,在这种情况下,为了保持您的应用程序(为了简单起见,我假设它是单线程的)响应,您必须有一种方法来异步触发更新,也许使用计时器。看看 glib 的 g_timeout_add() 函数来学习如何添加简单的全局计时器。

You need to get a GtkTreeIter to the proper row, then use the appropriate (model-specific) setter to change the data.

For instance gtk_list_store_set() for the GtkListStore model.

There is no need to clear the entire model if you just want to change some of the data, that is very wasteful and slow.

If you really need to change all the data, then sure, clear it.

You don't have to worry about getting the display to refresh; the view listens to events from the model, and automatically knows to refresh when the model changes.

UPDATE:

When changing the data (as described in commment), you don't need to "flush" the old data. The model owns the data, and knows how to keep track of the memory used. You just use the above-mentioned gtk_list_store_set() call as necessary to put the new desired data in the model. You can do this as often as necessary, and an update frequency of once every few seconds should be no problem at all.

Of course, in such a case, to keep your application (which I assume is single-threaded, for simplicity) responsive, you must have a way to asynchronously trigger an update, perhaps using a timer. Have a look at glib's g_timeout_add() function to learn how to add a simple global timer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文