Re: GtkTreeView having nodes with underlined text



On Wed, Nov 22, 2006 at 01:28:32PM +0100, Miroslav Rajcic wrote:
I am having a problem to underline text for some (not all) nodes in a 
GtkTreeView.

I've tried following:

1. a) add new column in the tree store of type G_TYPE_ENUM (tried integer 
type too)

Should be G_TYPE_UINT.

    b) attach text renderer to this store column:

gtk_tree_view_column_set_attributes(column, renderer,
   "underline", STORE_IDX_UNDERLINE,
   NULL);

Should be gtk_tree_view_column_add_attribute().

Unfortuantely, this does not work. I even added a store column for 
"underline-set", and attached the renderer property to that store col.

I'm not quite sure what the logic behind foo-set properties
is either, but setting them to TRUE at the begining and the
just changeing the actual property does what one normally
wants.

GValue             value = { 0, };
g_value_init (&value, PANGO_TYPE_UNDERLINE);
g_value_set_enum (&value, PANGO_UNDERLINE_SINGLE);
g_object_set_property (G_OBJECT (renderer), "underline", &value);
g_value_unset (&value);

This is a bit overengineered.

  g_object_set(renderer, "underline", PANGO_UNDERLINE_SINGLE, NULL);

does exactly the same.

Does anyone have the code to set underline font for arbitrary node in a tree 

No, but can easily make some.

Yeti


--
Whatever.


===========================================================================
#include <string.h>
#include <gtk/gtk.h>

enum { COL_TEXT, COL_ULINE };

int
main(int argc, char *argv[])
{
    static const gchar *text[] = {
        "Foo", "Bar", "Baz", "Quux", "Bloody", "Underline",
    };
    GtkTreeViewColumn *column;
    GtkCellRenderer *renderer;
    GtkListStore *store;
    GtkTreeIter iter;
    GtkWidget *window, *view;
    PangoUnderline uline;
    guint i;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), -1, 300);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_UINT);
    for (i = 0; i < G_N_ELEMENTS(text); i++) {
        if (strchr(text[i], 'a'))
            uline = PANGO_UNDERLINE_DOUBLE;
        else if (strchr(text[i], 'o'))
            uline = PANGO_UNDERLINE_SINGLE;
        else
            uline = PANGO_UNDERLINE_NONE;
        gtk_list_store_append(store, &iter);
        gtk_list_store_set(store, &iter,
                           COL_TEXT, text[i],
                           COL_ULINE, uline,
                           -1);
    }

    view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
    gtk_container_add(GTK_CONTAINER(window), view);

    renderer = gtk_cell_renderer_text_new();
    g_object_set(renderer, "underline-set", TRUE, NULL);
    column = gtk_tree_view_column_new_with_attributes("Text", renderer,
                                                      "text", COL_TEXT,
                                                      "underline", COL_ULINE,
                                                      NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}



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