Hello and welcome to the GTK+ forums!
You're having troubles because you don't fully understand how tree view works. Tree view can be seen as a empty piece of paper that is divided vertically into columns (column is represented by GtkTreeViewColumn) and horizontally into rows (you then actually get a grid). The actual content of tree view is then directly drawn on this paper by cell renderer. Cell renderer functions like
rubber stamp where you set the attributes and then paint one cell of the grid. So it's operation can be described in pseudo-code like this:
- set proper attributes on cell renderer
- stamp contents into proper place
- move to next cell
- repeat from 1
It should be clear now that you cannot use widgets (or widget trees) when it comes to tree view.
Now, to solve your problem. There are three solutions available to this problem. The easiest one is to simply store the complete text in one column in your data store and embed a newline character directly inside it. This is really simply to implement, but complexity comes if you need to update just the second line, since now you'll need to hammer the string into something reasonable.
Second option is to store upper and lower strings in separate columns inside data store and then use cell data function to combine them at render time. This is a bit more complex to set up and will tax the performance of your application a bit, but now it's easy to modify only upper or lower text.
Third (and the best option) would be to create custom cell renderer, but this requires some work and knowledge of GObject and GType. I don't think this is feasible to achieve with your level of knowledge right now, but with a little hard work this can be changed.
Now, just to give you a quick boost, I created a sample app for the second approach (implementations of the first and third one are left as a practice/learning opportunity ) that demo's how to use cell data functions.
Code:
#include <gtk/gtk.h>
enum
{
C_PIXBUF = 0,
C_UP_TEXT,
C_DOWN_TEXT,
NO_COLS
};
static void
glue_text (GtkTreeViewColumn *col,
GtkCellRenderer *cell,
GtkTreeModel *model,
GtkTreeIter *iter)
{
char *title, *text;
char *markup;
gtk_tree_model_get (model, iter, C_UP_TEXT, &title,
C_DOWN_TEXT, &text, -1);
markup = g_strdup_printf ("<b><big>%s</big></b>\n%s", title, text);
g_object_set (cell, "markup", markup, NULL);
g_free (title);
g_free (text);
g_free (markup);
}
int
main (int argc,
char **argv)
{
GtkWidget *window,
*treeview;
GtkListStore *store;
GtkCellRenderer *cell;
int i;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
store = gtk_list_store_new (NO_COLS, GDK_TYPE_PIXBUF,
G_TYPE_STRING, G_TYPE_STRING);
for (i = 1; i < 10; i++)
{
GtkTreeIter iter;
char line1[] = "Title in row ";
char line2[] = "Text in row ";
GdkPixbuf *pbuf;
line1[13] = line2[12] = '0' + i;
pbuf = gtk_widget_render_icon_pixbuf (window,
GTK_STOCK_DIALOG_INFO,
GTK_ICON_SIZE_DIALOG);
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, C_PIXBUF, pbuf,
C_UP_TEXT, line1, C_DOWN_TEXT, line2, -1);
g_object_unref (pbuf);
}
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
gtk_container_add (GTK_CONTAINER (window), treeview);
g_object_unref (store);
cell = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, "Image", cell,
"pixbuf", C_PIXBUF,
NULL);
cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (treeview),
-1, "Text", cell,
(GtkTreeCellDataFunc)glue_text,
NULL, NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Cheers,
Tadej