RE: Gtk2: GtkCellRendererText: changing bgcolor based on..
- From: "Erik Simonsen" <erik pinksheets com>
- To: "Geert Vanderkelen" <geert ypsilon net>, "gtk-app-devel" <gtk-app-devel-list gnome org>
- Subject: RE: Gtk2: GtkCellRendererText: changing bgcolor based on..
- Date: Fri, 13 Sep 2002 11:15:23 -0400
You can, at the expense of some memory, make color management easier by just
using strings. This treeview has more than just a text column, but i hope
it's still clear--you can just leave out the columns you don't want. My
treeview just happens to need an icon as well.
enum{
FILE_TREE_IMAGE_COLUMN,
FILE_TREE_TEXT_COLUMN,
FILE_TREE_DATA_COLUMN,
FILE_TREE_COLOR_COLUMN,
NUM_COLUMNS
};
GtkWidget *tree;
GtkTreeSelection *select;
GtkTreeStore *playlist_store;
GtkCellRenderer *text_renderer;
GtkCellRenderer *pixbuf_renderer;
GtkTreeViewColumn *column;
/* I create a store with a an image column (that holds my pixbufs), a text column for the text, a pointer
column that just holds my own data--you can ignore that--and a color column, that holds strings. */
playlist_store = gtk_tree_store_new (NUM_COLUMNS,
GDK_TYPE_PIXBUF, /*FILE_TREE_IMAGE_COLUMN*/
G_TYPE_STRING, /*FILE_TREE_TEXT_COLUMN*/
G_TYPE_POINTER, /*FILE_TREE_DATA_COLUMN*/
G_TYPE_STRING /*FILE_TREE_COLOR_COLUMN*/
);
/* create the renderers-- The pixbuf renderer here is just because I needed an icon in my treeview, you can
leave it out*/
text_renderer = gtk_cell_renderer_text_new();
pixbuf_renderer = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(column, pixbuf_renderer, FALSE);
gtk_tree_view_column_add_attribute (column, pixbuf_renderer,
"pixbuf", FILE_TREE_IMAGE_COLUMN);
/* This will associate the background color of the text renderer with the Color column of my store */
gtk_tree_view_column_pack_end(column, text_renderer, TRUE);
gtk_tree_view_column_add_attribute (column, text_renderer,
"text", FILE_TREE_TEXT_COLUMN);
gtk_tree_view_column_add_attribute (column, text_renderer,
"background", FILE_TREE_COLOR_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
. . .
/*When you add a row to the store, just add the color of the row as a string into that last column. No need
to deal with gdkcolors and allocations, etc.*/
gtk_tree_store_set ( playlist_store, &iter,
FILE_TREE_TEXT_COLUMN, "column text",
FILE_TREE_IMAGE_COLUMN, minfo->icon,
FILE_TREE_DATA_COLUMN, (gpointer) minfo,
FILE_TREE_COLOR_COLUMN, "white",
-1);
For the color column part, you can use several formats: "white", "#202020", and i think "{ .4 .5 .2}" are
all valid formats. easy peasy.
Hope this helped!
Erik Simonsen
homelessgoats.com
-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org]On Behalf Of Geert
Vanderkelen
Sent: Thursday, September 12, 2002 10:16 AM
To: gtk-app-devel
Subject: Gtk2: GtkCellRendererText: changing bgcolor based on..
Hi,
It's a GTK-2.0 question, so I'm not sure if I have to use this
mailinglist.. :)
Anyway. I have a GtkTreeView with a GtkListStore and such. It updates
every 300ms (query to database, get rows, show rows). It's a monitoring
system. It's running really great, and I'm not sure if I can make it
faster with other widgets.
To make it more appealing, the cells should have colors. Like a time
cell > 5 secs.. color red and so on.
Now, I can set the cell color with g_object_set().. But I want to do
this when updating the Store.. So on the fly a color where a column can
have let's say 5 different colors.. you know.
I tried to set the property in the iteration making the list, but I'm
not successful. Probably it is not placed correctly.
So, do I need to write a new GtkCellRenderer that can based on the value
the cell has, change it's backgroundcolor. Or can I do it with
GtkCellRendererText?
You know, a signal like 'changed' instead of 'edited' would be great :)
Thanks!
Geert
--
Geert Vanderkelen
Ypsilon.Net AG
http://www.ypsilon.net
_______________________________________________
gtk-app-devel-
list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]