Re: [gtkmm] Setting the background color of a specific cell in a Gtk::Treeview

I understand that I have to change the cellrender for that cell but the problem is that I don't know how to get to the CellRenderer - what I have is a TreeViewColumn and a TreeModelRow and from those two I need to get at the CellRenderer. Any ideas ?

Here is some code to show hot to change the color for an entire column:
class ModelColumns : public Gtk::TreeModel::ColumnRecord
    ModelColumns()  {   add(m_col_i);    add(m_col_visible);  
  Gtk::TreeModelColumn<int> m_col_i;
  Gtk::TreeModelColumn<bool> m_col_visible;

ModelColumns m_Columns;
Gtk::TreeView m_TreeView;
Glib::RefPtr<Gtk::TreeStore> m_refTreeModel;

m_refTreeModel = Gtk::TreeStore::create(m_Columns);

// Add a row with data
Gtk::TreeModel::Row row = *(m_refTreeModel->append());
row[m_Columns.m_col_i] = 99;
row[m_Columns.m_col_visible] = false;

// Append the column
int cols_count  = m_TreeView.append_column("i", m_Columns.m_col_i);
Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count-1);
    // Set the background color for the entire column
   Gtk::CellRendererText* pRenderer = static_cast<Gtk::CellRendererText*>(pColumn->get_first_cell_renderer());
   Gdk::Color col("red");
   pColumn->add_attribute(renderer->property_visible(), m_Columns.m_col_visible); 

Jarek Dukat wrote:
On Thu, 2003-01-09 at 17:56, Liza Klerck wrote:
I have a [Gtk::TreeViewColumn] and a [Gtk::TreeModel::Row] - how do I 
get to the cellrenderer in order to set the background color of this
specific cell for this column and row in a Gtk::Treeview ? I need to set
and reset background colors for specific cells on certain events. I
understand how to set the background color of an entire column but need
to know how to set it for individual cells.

For single cell you must change background color property of the cell
renderer inside that cell.
Could you please tell us how you do it for entire column?

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