Re: GtkTreeView only displays one column
In [EMAIL PROTECTED], Tony Houghton wrote: I'm trying to use GtkTreeView with GtkListStore to show a list of rows, each containing a radio button and a bit of text (file leafname). The trouble is I can only get the TreeView to show one column at a time. I've distilled my code down to a standalone program. Hopefully now someone else will easily be able to play with it and see what's wrong. FWIW I'm using libgtk+ 2.8.6 from Ubuntu Breezy. Same problem on x86 and x86_64. #include gtk/gtk.h #define N_ITEMS 10 #define USE_SCROLL 1 static void destroy_handler(GtkObject *o, void *d) { gtk_main_quit(); } enum { Column_Radio, Column_Name, Column_NColumns }; static void populate_list(GtkListStore *list) { int n; for (n = 0; n N_ITEMS; ++n) { GtkTreeIter iter; char *s = g_strdup_printf(Item %d, n); gtk_list_store_append(list, iter); gtk_list_store_set(list, iter, Column_Radio, n == 1, Column_Name, s, -1); g_free(s); } } static GtkWidget *create_list_widget(void) { GtkTreeViewColumn *rcolumn, *tcolumn; GtkCellRenderer *radio; GtkWidget *widget; GtkTreeView *tvw; GtkListStore *list; widget = gtk_tree_view_new(); tvw = GTK_TREE_VIEW(widget); list = gtk_list_store_new(Column_NColumns, G_TYPE_BOOLEAN, G_TYPE_STRING); gtk_tree_view_set_model(tvw, GTK_TREE_MODEL(list)); radio = gtk_cell_renderer_toggle_new(); gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(radio), TRUE); rcolumn = gtk_tree_view_column_new_with_attributes( Radio, radio, active, Column_Radio, NULL); gtk_tree_view_column_set_sizing(rcolumn, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column(tvw, rcolumn); tcolumn = gtk_tree_view_column_new_with_attributes( Name, gtk_cell_renderer_text_new(), text, Column_Name, NULL); gtk_tree_view_column_set_sizing(tcolumn, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column(tvw, tcolumn); gtk_tree_selection_set_mode(gtk_tree_view_get_selection(tvw), GTK_SELECTION_BROWSE); populate_list(list); return widget; } int main(int argc, char **argv) { GtkWidget *main_win, *tvw, *scroll; gtk_init(argc, argv); main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(main_win, destroy, G_CALLBACK(destroy_handler), NULL); tvw = create_list_widget(); #if defined USE_SCROLL USE_SCROLL scroll = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(main_win), scroll); gtk_container_add(GTK_CONTAINER(scroll), tvw); #else gtk_container_add(GTK_CONTAINER(main_win), tvw); #endif gtk_widget_show_all(main_win); gtk_main(); return 0; } -- TH * http://www.realh.co.uk ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkTreeView only displays one column
On Mon, Jan 09, 2006 at 02:23:08PM +, Tony Houghton wrote: I've distilled my code down to a standalone program. Hopefully now someone else will easily be able to play with it and see what's wrong. The column becomes visible when you (a) do not set sizing mode to GTK_TREE_VIEW_COLUMN_FIXED (b) actually give the first column a fixed width 0 with gtk_tree_view_column_set_fixed_width() While that makes kind of sense I cannot say I understand the logic behind... but I hope it helps anyway. Yeti -- That's enough. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: GtkTreeView only displays one column
In [EMAIL PROTECTED], you wrote: On Mon, Jan 09, 2006 at 02:23:08PM +, Tony Houghton wrote: I've distilled my code down to a standalone program. Hopefully now someone else will easily be able to play with it and see what's wrong. The column becomes visible when you (a) do not set sizing mode to GTK_TREE_VIEW_COLUMN_FIXED (b) actually give the first column a fixed width 0 with gtk_tree_view_column_set_fixed_width() While that makes kind of sense I cannot say I understand the logic behind... but I hope it helps anyway. Yes, I've just discovered that trying to use fixed sizes is the cause of the problem and that the sizing seems OK if I just ignore it altogether. -- TH * http://www.realh.co.uk ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
GtkTreeView only displays one column
I'm trying to use GtkTreeView with GtkListStore to show a list of rows, each containing a radio button and a bit of text (file leafname). The trouble is I can only get the TreeView to show one column at a time. The bits of code I'm using to do this are: enum { cfColumn_Radio, cfColumn_Name, cfColumn_NColumns }; static void configlet_list_build(ConfigletList *cl) { DynamicOptions *dynopts; char **file_list; char **file; const char *selected_name = configlet_get_configured_name(cl); if (cl-list) { gtk_list_store_clear(cl-list); } else { cl-list = gtk_list_store_new(cfColumn_NColumns, G_TYPE_BOOLEAN, G_TYPE_STRING); } dynopts = dynamic_options_get(cl-family); file_list = dynamic_options_list(dynopts); for (file = file_list; *file; ++file) { GtkTreeIter iter; gtk_list_store_append(cl-list, iter); gtk_list_store_set(cl-list, iter, cfColumn_Radio, !strcmp(selected_name, *file), cfColumn_Name, *file, -1); } g_strfreev(file_list); } static void configlet_list_init(ConfigletList *cl, GtkWidget *widget, Options *options, const char *family) { GtkTreeViewColumn *rcolumn, *tcolumn; GtkCellRenderer *radio; cl-tvwidget = GTK_TREE_VIEW(widget); cl-options = options; cl-family = family; cl-list = gtk_list_store_new(cfColumn_NColumns, G_TYPE_BOOLEAN, G_TYPE_STRING); gtk_tree_view_set_model(cl-tvwidget, GTK_TREE_MODEL(cl-list)); radio = gtk_cell_renderer_toggle_new(); gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(radio), TRUE); rcolumn = gtk_tree_view_column_new_with_attributes( NULL, radio, active, cfColumn_Radio, NULL); gtk_tree_view_column_set_sizing(rcolumn, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column(cl-tvwidget, rcolumn); tcolumn = gtk_tree_view_column_new_with_attributes( NULL, gtk_cell_renderer_text_new(), text, cfColumn_Name, NULL); gtk_tree_view_column_set_sizing(tcolumn, GTK_TREE_VIEW_COLUMN_FIXED); gtk_tree_view_append_column(cl-tvwidget, tcolumn); gtk_tree_view_column_set_visible(rcolumn, TRUE); gtk_tree_selection_set_mode(gtk_tree_view_get_selection(cl-tvwidget), GTK_SELECTION_BROWSE); configlet_list_build(cl); configlet_select_name(cl, configlet_get_configured_name(cl)); gtk_widget_realize(widget); gtk_tree_view_columns_autosize(cl-tvwidget); } On entry to configlet_list_init, widget has been looked up by glade and is a GtkTreeView contained by a GtkScrolledWindow with H Policy = Automatic and V Policy = Always. I've tried lots of different things, like adding extra columns, adding them in reverse order using insert instead of append, but it always only displays the rightmost visible column. Forcing rcolumn to be visible doesn't help, but if I make tcolumn invisible, it does display rcolumn instead. The last two lines are what I added to see if that would help, but it didn't. I must be doing something wrong, but I can't see how the above differes fundamentally from the example at http://developer.gnome.org/doc/API/2.0/gtk/TreeWidget.html. Can anyone help? -- TH * http://www.realh.co.uk ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list