Re: GtkTreeView only displays one column
- From: Tony Houghton <h realh co uk>
- To: gtk-app-devel-list gnome org
- Subject: Re: GtkTreeView only displays one column
- Date: Mon, 9 Jan 2006 14:23:08 +0000
In <20060108225206 GA7660 realh co uk>, 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]