Sortable Treeview
- From: Rudra Banerjee <bnrj rudra yahoo com>
- To: gtk devel <gtk-app-devel-list gnome org>
- Subject: Sortable Treeview
- Date: Sun, 07 Oct 2012 00:25:22 +0100
Dear friends,
I am trying to make a Treeview sortable. I have managed to get sortable
by any one column, using
GtkTreeSortable *sortable=GTK_TREE_SORTABLE(data->store);
Code:
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortable),
ID_YEAR, GTK_SORT_ASCENDING);
which will by default sort by year(or any ID_* that appear last), and
treeview will get that view.
What I am looking for, is make my header clickable to get the sorting,
with initial view completely unsorted.
I only managed to found this information:
but I have no idea how.
Can you kindly help a bit,
typedef struct _Data
{
GtkWidget *window;
GtkListStore *store;
}
Data;
enum
{
C_TYPE = 0,
C_NAME,
C_YEAR,
C_TITLE,
NO_COLS
};
enum
{
ID_TYPE = 0,
ID_NAME,
ID_YEAR,
ID_TITLE
};
static void
create_gui (Data *data)
{
GtkWidget *vbox,
*cbutton,
*swindow,
*tree;
GtkCellRenderer *cell;
data->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (data->window), 400, 400);
g_signal_connect (data->window, "destroy", gtk_main_quit, NULL);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
gtk_container_add (GTK_CONTAINER (data->window), vbox);
cbutton = gtk_file_chooser_button_new ("Load bib file",
GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (cbutton, "file-set", G_CALLBACK (cb_file_set),
data);
gtk_box_pack_start (GTK_BOX (vbox), cbutton, FALSE, FALSE, 0);
swindow = gtk_scrolled_window_new (NULL, NULL);
gtk_box_pack_start (GTK_BOX (vbox), swindow, TRUE, TRUE, 0);
data->store = gtk_list_store_new (NO_COLS, G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
GtkTreeSortable *sortable=GTK_TREE_SORTABLE(data->store);
/* gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortable),
ID_NAME, GTK_SORT_ASCENDING);
*/
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortable),
ID_YEAR, GTK_SORT_ASCENDING);
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (data->store));
gtk_container_add (GTK_CONTAINER (swindow), tree);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
"Type", cell,
"text", C_TYPE,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
"Name", cell,
"text", C_NAME,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
"Year", cell,
"text", C_YEAR,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1,
"Title", cell,
"text", C_TITLE,
NULL);
gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(tree),TRUE);
gtk_widget_show_all (vbox);
}
Report this post
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]