GtkTreeView 中的数据不按字母顺序排序?

发布于 2024-08-29 07:23:50 字数 906 浏览 2 评论 0原文

我正在尝试按非字母顺序对 GTK 树视图中的一列数据进行排序。我似乎无法在 GTK+ 库中找到无法执行此类操作的函数。

这里有人知道有办法做到这一点吗?

更新:

下面是我当前尝试使用的代码:

column = gtk_tree_view_column_new();

gtk_tree_view_column_set_title(column, "Memory");

gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_reorderable(column, TRUE);
gtk_tree_view_column_set_sort_indicator(column, TRUE);
/**********************************************************
gtk_tree_view_column_set_sort_column_id(column, 3);
gtk_tree_sortable_set_sort_column_id(column, 3, GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
**********************************************************/

gtk_tree_view_append_column(GTK_TREE_VIEW(rendered_view), column);

c_renderer = gtk_cell_renderer_text_new();

gtk_tree_view_column_pack_start(column, c_renderer, TRUE);

gtk_tree_view_column_add_attribute(column, c_renderer, "text", MEMORY);

I'm trying to sort a column of data in a GTK tree view non-alphabetically. I can't seem to find a function in the GTK+ libraries that cant do such a thing.

Does anyone here know of a way to do this?

UPDATE:

Below is the code im currently trying to use:

column = gtk_tree_view_column_new();

gtk_tree_view_column_set_title(column, "Memory");

gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_column_set_reorderable(column, TRUE);
gtk_tree_view_column_set_sort_indicator(column, TRUE);
/**********************************************************
gtk_tree_view_column_set_sort_column_id(column, 3);
gtk_tree_sortable_set_sort_column_id(column, 3, GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID);
**********************************************************/

gtk_tree_view_append_column(GTK_TREE_VIEW(rendered_view), column);

c_renderer = gtk_cell_renderer_text_new();

gtk_tree_view_column_pack_start(column, c_renderer, TRUE);

gtk_tree_view_column_add_attribute(column, c_renderer, "text", MEMORY);

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

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

发布评论

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

评论(1

迷迭香的记忆 2024-09-05 07:23:50

请参阅 GtkTreeSortable 接口,它允许您可以设置自定义排序功能。

请注意,常用的标准 GtkListStore模型实现了 GtkTreeSortable。

您可能还需要调用 gtk_tree_sortable_set_sort_column_id() 选择要排序的列。这使用了“排序列id”的概念,这与列索引不同。创建各个 GtkTreeViewColumn 时,您需要使用 gtk_tree_view_column_set_sort_column_id()

本教程可能值得一读,以便更好地理解所涉及的概念。

See the GtkTreeSortable interface, which allows you to set your custom sorting function.

Notice that the commonly used standard GtkListStore model implements GtkTreeSortable.

You might also need to call gtk_tree_sortable_set_sort_column_id() to select which column to sort on. This uses the concept of "sort column id", which is not the same as column index. You need to set the proper column id on the individual GtkTreeViewColumns when you create them, using gtk_tree_view_column_set_sort_column_id().

This tutorial might be good reading, to get a better understanding of the concepts involved.

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