GtkTreeView: packing two renderers in one column



Hi

I'm writing an application that uses a GtkTreeView. I
packed two renderers in the first column. I want to
set the background color of certain tree rows to
different colors.

The problem is that the background color of the second
renderer is drawn on top of part of the contents of
the first renderer. It also seems that the width of
this part is equal to the indentation used to epresent
the tree hierarchy, including the expander.

I understand why GTK indents every cell renderer in a
column, but what can I do to make it render the
backgrounds correctly?

Here is the complete source code:

#include <gnome.h>

enum {
    COL_COLUMN_1 = 0,
    COL_COLUMN_2,
    COL_BACKGROUND,
    NUM_COLS
};

int main(int argc, char **argv)
{
    GtkWidget   *toplevel, *view, *main_box;


    gnome_init("app", "0.0", argc, argv);

    toplevel = gnome_app_new("app", "Testing GTK
Tree");

    main_box = gtk_hbox_new(FALSE, 0);
    gnome_app_set_contents(GNOME_APP(toplevel),
main_box);

    view = create_view_and_model();

    gtk_box_pack_start(GTK_BOX(main_box), view, TRUE,
TRUE, 0);
    gtk_widget_show_all(toplevel);
    gtk_main();

    return 0;
}

static GtkWidget *create_view_and_model(void)
{
    GtkTreeIter         iter, iter2;
    GtkTreeViewColumn   *col;
    GtkCellRenderer     *renderer;
    GtkWidget           *view;
    GtkTreeStore        *model;


    /* Tree view
---------------------------------------------*/
    view = gtk_tree_view_new();
    col = gtk_tree_view_column_new();
    gtk_tree_view_column_set_title(col, "Column
title");
    
    /* First renderer */
    renderer = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(col, renderer,
FALSE);
    gtk_tree_view_column_set_attributes(col, renderer,

                        "text",            COL_COLUMN_1,
                        "cell-background",
COL_BACKGROUND,
                        NULL);

    /* Second renderer */
    renderer = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(col, renderer,
TRUE);
    gtk_tree_view_column_set_attributes(col, renderer,
                        "text",           
COL_COLUMN_2,
                        "cell-background",
COL_BACKGROUND,
                        NULL);

    gtk_tree_view_column_set_reorderable(col, FALSE);
    gtk_tree_view_column_set_resizable(col, TRUE);
    gtk_tree_view_column_set_sizing(col,
GTK_TREE_VIEW_COLUMN_GROW_ONLY);
    gtk_tree_view_append_column(GTK_TREE_VIEW(view),
col);

    /* Tree model
--------------------------------------------*/
    model = gtk_tree_store_new(NUM_COLS,
                        G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);

    gtk_tree_store_append(model, &iter, NULL);
    gtk_tree_store_set(model, &iter,
                COL_COLUMN_1,   "Some string",
                COL_COLUMN_2,   "Level 1",
                COL_BACKGROUND, "Gray",
                -1);
        
    gtk_tree_store_append(model, &iter2, &iter);
    gtk_tree_store_set(model, &iter2,
                COL_COLUMN_1,   "Some string",
                COL_COLUMN_2,   "Level 3",
                COL_BACKGROUND, "Yellow",
                -1);

    gtk_tree_view_set_model(GTK_TREE_VIEW(view),
GTK_TREE_MODEL(model));
    return view;
}

__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]