在Gtk中,如何在包含特定值的行中搜索ListStore? [英] In Gtk, how do I search a ListStore for the row containing a particular value?

查看:309
本文介绍了在Gtk中,如何在包含特定值的行中搜索ListStore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ListStore 建模 Tag s的列表。除了 ListStore 以外,这个列表可能会改变。我想要做的是听我的 TagList 类中的 TagRemoved 事件,并移除<$ c当触发事件时,从 ListStore 中添加$ c> Tag 。然而,我似乎无法找到一个方法来搜索 ListStore 包含给定标记的行,所以我可以删除它。

I have a ListStore modeling a list of Tags. This list may change apart from the ListStore. What I'd like to do is listen to the TagRemoved event in my TagList class, and remove the Tag from the ListStore when the event is triggered. However, I can't seem to find a way to search a ListStore for the row containing a given Tag, so that I can remove it.

有没有办法做到这一点?

Is there any way to do this?

推荐答案

GtkListStore 实现 GtkTreeModel 接口,其中包含所需的树遍历操作。据我所知,没有便利的API搜索列表/树存储,所以你必须推出自己的。

A GtkListStore implements the GtkTreeModel interface, which contains the tree traversal operations you want. As far as I know, there is no convenience API for searching a list/tree store, so you'll have to roll your own.

因为你只是迭代通过 GtkListStore ,你可以忽略所有处理子/父关系的API,并简单地使用 gtk_tree_model_iter_first() gtk_tree_model_iter_next()来遍历列表。

Since you're simply iterating over a GtkListStore, you can ignore all of the API dealing with child/parent relations, and simply use gtk_tree_model_iter_first() and gtk_tree_model_iter_next() to traverse the list.

或者,如果您已经知道已删除标记的索引(例如,从 TagRemoved 事件),您可以将其转换为 GtkTreePath 并使用 gtk_tree_model_get_iter()直接检索相关行而不需要搜索。

Alternatively, if you already know the index of the removed tag in the store (e.g., from your TagRemoved event), you can turn that into a GtkTreePath and use gtk_tree_model_get_iter() to retrieve the row in question directly without searching.

这篇关于在Gtk中,如何在包含特定值的行中搜索ListStore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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