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);
See the
GtkTreeSortableinterface, which allows you to set your custom sorting function.Notice that the commonly used standard
GtkListStoremodel 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.