Re: Coloring specific rows in a Gtk::TreeView



It's the same thing, just that you check which column you are in.
Adapting the previous example gives this:

 int colNum = treeView.append_column("Foo", m_columns.m_foo) - 1;

 treeView.get_column(colNum)->set_cell_data_func(*treeView .get_column_cell_renderer(colNum),
                      sigc::bind(sigc::mem_fun(*this, &Foo::set_verdict_color), colNum));

void Foo::set_verdict_color(
  Gtk::CellRenderer* cell,
  const Gtk::TreeModel::iterator& iter,
  int colNum,
)
{
 // implement getBackgroundColor!!!
 const char *bkCol = getBackgroundColor(*iter, colNum);
 cell->property_cell_background() = bkCol;
}

Where getBackgroundColor would get the color for the given column in that given cell (based on iter and colNum); one could think of additional qualifiers to pass to getBackgroundColor.



2008/7/30 Sai <rsaikamesh gmail com>
Hi,

Thanks a lot for the reply.

I tried this out. But it colors all the cells in a column. But the need is coloring specific cells among all the cells in the column (depending upon the value stored in the rows). ( A column can have many rows, among all these rows very few need to be colored ). Can you please give me some ideas on this?



On Wed, Jul 30, 2008 at 7:26 PM, Andris Pavenis <andris pavenis iki fi> wrote:
Sai wrote:
Hi,

Is coloring specific rows in a Gtk::TreeView possible ?. If yes please tell me how. I have no clue on how to color specific rows.

Yes. Here is editted example for  coloring  cells of single column depending on content (like 'OK' green and 'ERROR' red).

 int colNum = treeView.append_column("Foo", m_columns.m_foo) - 1;

 treeView.get_column(colNum)->
  set_cell_data_func(*treeView .get_column_cell_renderer(colNum),
                      sigc::mem_fun(*this, &Foo::set_verdict_color));



void Foo::set_verdict_color(Gtk::CellRenderer* cell,
                                               const Gtk::TreeModel::iterator& iter)
{
 // implement getBackgroundColor!!!
 const char *bkCol = getBackgroundColor(*iter);
 cell->property_cell_background() = bkCol;
}

One can change foreground color in the same way.
(Copied example from own program and editted)




_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list




--
------------
Please note that according to the German law on data retention,
information on every electronic information exchange with me is
retained for a period of six months.
[Bitte beachten Sie, dass dem Gesetz zur Vorratsdatenspeicherung zufolge
jeder elektronische Kontakt mit mir sechs Monate lang gespeichert wird.]


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