Re: success with GtkTreeView
- From: Scott Andrew Baillie <sbaillie bigpond net au>
- To: gtk-list gnome org
- Subject: Re: success with GtkTreeView
- Date: 03 Jan 2003 11:02:22 +0000
On Thu, 2003-01-02 at 02:14, Carl B. Constantine wrote:
Ok, you can ignore my previous message. I did get it work by creating
another project (gtk2 only) and copy/paste the relevant code bits in.
The good news is I used Glade to create a GtkTreeView object. I then
grabbed a pointer to that object using lookup_widget, created a
GtkListStore and set the GtkTreeView up to use that list store. I then
started creating columns and adding them as showin in "Tree and List
Widget" in the Gtk+ 2.0 API docs on the website, and also some help from
some of you (special thanks to Harring Figueirdo on the Glade-Users
list -- hmm, Figueirdo, is that Portuguese?)
However, one of the things I wanted to try was to set the heading text
to be red, like shown in the API reference, but for some reason it
doesn't work. See for yourself at:
http://www.duckwing.ca/screenshots/gtktreeview.jpg
Notice the code behind "window1" shows creating the cell renderer and
setting the text to red using g_object_set:
renderer = gtk_cell_renderer_text_new();
g_object_set( G_OBJECT(renderer), "foreground", "red", NULL);
but when I create the column and append it to the view, the text is not
red like I *thought* it should be:
column = gtk_tree_view_column_new_with_attributes("Shift",
renderer, "text", SHIFT_COLUMN, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(theTreeView), column);
This is pretty much straight from the API Reference docs. Any ideas as
to why this is happening? Do the headings for the columns maybe not
allow this?
Hi Carl,
I had the same problem with the red foreground that you did.
I did get it to work with a different method.
See following code :
void* TreeView_create_tree_model(void* object)
{
GtkTreeStore *treeStore;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GType* pType=g_malloc((1+STRING_COLUMN)*sizeof(GType));
GtkTreeView *treeView=(GtkTreeView*)object;
pType[POINTER_COLUMN]=G_TYPE_POINTER;
pType[FOREGROUND_COLUMN]=G_TYPE_STRING;
pType[FONT_COLUMN]=G_TYPE_STRING;
pType[STYLE_COLUMN]=G_TYPE_INT;
pType[WEIGHT_COLUMN]=G_TYPE_INT;
pType[BACKGROUND_COLUMN]=G_TYPE_STRING;
pType[STRING_COLUMN]=G_TYPE_STRING;
treeStore=gtk_tree_store_newv(1+STRING_COLUMN,pType);
g_free(pType);
gtk_tree_view_set_model(GTK_TREE_VIEW(treeView),GTK_TREE_MODEL(treeStore));
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("ColumnTitle",
renderer,
"text", STRING_COLUMN,
"foreground", FOREGROUND_COLUMN,
"font", FONT_COLUMN,
"style", STYLE_COLUMN,
"weight", WEIGHT_COLUMN,
"background", BACKGROUND_COLUMN,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeView),column);
return(treeStore);
}
void TreeView_set_foreground_attribute(void* treeModel,void* iter,const char* str)
{
GValue value = { 0 };
g_value_init(&value,G_TYPE_STRING);
g_value_set_string(&value,str);
gtk_tree_store_set_value((GtkTreeStore*)treeModel,(GtkTreeIter*)iter,FOREGROUND_COLUMN,&value);
}
Regards,
Scott.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]