Re: Changing foreground and background color in GtkListView rows



Thanks for your help, it's making things clearer. I should mention that I am porting a gtk+1.2.x gui to 2.4 
so I'm learning the new GtkTreeView model as I go.

I used the info from the tutorial at: http://scentric.net/tutorial/sec-treeview-col-whole-row.html and 
implemented it in the following way expanding on the code below:

{
....
   list_store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING,
                                                        G_TYPE_BOOLEAN);
   gtk_tree_view_set_model(GTK_TREE_VIEW(list_view), GTK_TREE_MODEL(list_store));
   renderer = gtk_cell_renderer_text_new();
   column = gtk_tree_view_column_new_with_attributes(var_list_col_title,
                                                       renderer,
                                                       "text", 0,
                                                       "foreground", 1,
                                                       "foreground-set", 2,
                                                       NULL);
....
}

And now the routine that updates the value and color in the model looks like this:

{
......
   if(NEWLY_CHANGED)
   {
      gtk_list_store_set(list_store, ITER,
                               0, DVAR->DISPLAYED_STR,
                               1, "Black",
                               2, TRUE,
                               -1);
   }
   else
   {
      gtk_list_store_set(list_store, ITER,
                               0, DVAR->DISPLAYED_STR,
                               1, "Red",
                               2, TRUE,
                               -1);
   }
....
}

when the routine is called for the first time the "Black" code runs and sets the color correctly, after the 
timer expires the "Red" code is called but the color stays in black. Am I doing this correctly?

Thanks again.


make the color part of your model. connect bg_color of renderer to the color
column in model and put the respective colors into the model.

http://scentric.net/tutorial/sec-treeview-col-whole-row.html

Stefan

marcodev comcast net wrote:
I have the following code creating the column and its renderer in the list:
{
......
     vars_list = gtk_tree_view_new ();
     renderer = gtk_cell_renderer_text_new();
     column = gtk_tree_view_column_new_with_attributes(var_list_col_title,
                                                       renderer,
                                                       "text", 0,
                                                       NULL);
     gtk_tree_view_append_column(GTK_TREE_VIEW(vars_list), column);
......
}

The list displays the values of variables in memory and is updated by a timout 
that runs periodically. When a variable is added (appended) to the list I use 
the following:

void
APPEND_TO_CLIST(GtkListStore *LIST, int ROW, char *STRING)
{
.....
   GtkTreeIter iter;

   gtk_list_store_append(LIST, &iter);
   gtk_list_store_set(LIST, &iter,
                      0, STRING,
                      -1);

   if(ROW % 2 == 0)
   {
      g_object_set(renderer, "background-gdk",
                                  MM_GLBL->COLORS.CLIST_BG_A, NULL);
   }
   else
   {
      g_object_set(renderer, "background-gdk",
                                  MM_GLBL->COLORS.CLIST_BG_B, NULL);
   }
....
}

The above however is not changing the color on the background as I expected 
it. Am I even doing this right?

The following issue might be related to the same problem I have with the code 
above, when the value of a variable in the list is updated the value should be 
displayed in one color (black) and when the value has remained unchanged for a 
period of time then it should switch to another color (red). This is the code I 
use for this:

void
UPDATE_CLIST_VALUE(GtkListStore *LIST, GtkTreeIter *ITER, char *STRING, 
                                        BOOLEAN NEWLY_CHANGED)
{
......
   if (NEWLY_CHANGED)
   {
      g_object_set(renderer, "foreground", "Black", NULL);
   }
   else
   {
      g_object_set(renderer, "foreground", "Red", NULL);
   }

   gtk_list_store_set(list_store, ITER,
                                0, STRING,
                            -1);
//   g_object_set(renderer, "text", STRING, NULL);
.......
}

The problem I have here is that when the color is chaned in the renderer and I 
set the value in the store to a specific ITER then the entire column changes 
color, I need to have only ONE iter (row) to change color as requested.

Any suggestions?

Thanks!!
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


-- 
      \|/            Stefan Kost
     <@ @>           private            business
+-oOO-(_)-OOo------------------------------------------------------ - - -  -   -
|       __  Address  Simildenstr. 5     HTWK Leipzig, Fb IMN, Postfach 301166
|      ///           04277 Leipzig      04251 Leipzig
| __  ///            Germany            Germany
| \\\///    Phone    +49341 2253538     +49341 30766101
|  \__/     EMail    st_kost_at_gmx.net kost_at_imn.htwk-leipzig.de
|           WWW      www.sonicpulse.de  www.imn.htwk-leipzig.de/~kost/about.html
===-=-=--=---=---------------------------------- - - -  -    -



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