On Thu, Jul 14, 2005 at 12:31:11PM -0500, Nickolai Dobrynin wrote: > Is there any way I can display four numbers in a single TreeView cell so that > each individual number would occupy the upper left, upper right, lower left > and > lower right corner, respectively: > ___________ > | 1 2 | > | | > | 3 4 | > ------------------
(hint: use a fixed-witdh font when drawing ASCII-art.) > It's kind of like a table inside another table. I would also like to > control the justification (left/right/center). > > Perhaps there is a way to display a TreeView inside another TreeView? > Since my "inner" table is fairly simple, perhaps I could get away with > something less complicated than that? You can pack two cell renderes into one column and put two-line texts to them. This is a dirty trick and aligning will work as expected only if the texts are of equal width, otherwise you have to take up with left alignment. See attached example. The ultimate solution is to write your own cell renderer. Yeti -- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? ============================================================================ #include <gtk/gtk.h> enum { COLUMN_1, COLUMN_2, COLUMN_3, N_COLUMNS }; static void fill_model(GtkListStore *store) { GtkTreeIter iter; gint i; gchar s[4] = ".\n."; for (i = 0; i < 6; i++) { gtk_list_store_append(store, &iter); s[0] = g_random_int_range('0', '9'+1); s[2] = g_random_int_range('0', '9'+1); gtk_list_store_set(store, &iter, COLUMN_1, s, -1); s[0] = g_random_int_range('0', '9'+1); s[2] = g_random_int_range('0', '9'+1); gtk_list_store_set(store, &iter, COLUMN_2, s, -1); s[0] = g_random_int_range('0', '9'+1); s[2] = g_random_int_range('0', '9'+1); gtk_list_store_set(store, &iter, COLUMN_3, s, -1); } } static void cell_data_func(G_GNUC_UNUSED GtkTreeViewColumn *tree_column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { guint col = GPOINTER_TO_UINT(data); gchar *s; gtk_tree_model_get(tree_model, iter, col, &s, -1); g_object_set(G_OBJECT(renderer), "text", s, NULL); g_free(s); } int main(int argc, char *argv[]) { GtkWidget *window, *view; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkListStore *store; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); fill_model(store); view = gtk_tree_view_new(); gtk_container_add(GTK_CONTAINER(window), view); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); column = gtk_tree_view_column_new(); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "xalign", 0.0, NULL); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_cell_data_func(column, renderer, &cell_data_func, GUINT_TO_POINTER(COLUMN_1), NULL); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "xalign", 0.5, NULL); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_cell_data_func(column, renderer, &cell_data_func, GUINT_TO_POINTER(COLUMN_2), NULL); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_cell_data_func(column, renderer, &cell_data_func, GUINT_TO_POINTER(COLUMN_3), NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); gtk_widget_show_all(window); gtk_main(); return 0; } _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list