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

Murray Cumming wrote:

On Fri, 2003-01-10 at 03:31, Liza Klerck wrote:

I'm sorry, some confusion occured in the message. The code example I included was a response to someone asking how to set the color of an entire column.

My question still remains, if I have a TreeViewColumn variable and a TreeModelRow variable how do I use those to get at the cell's cellrender ? The cell being represented by the intersection of the TreeViewColumn and the TreeModelRow.

You do not usually access the data via a CellRenderer directly - data
should be set in the model. You just use an appropriate, or
appropriately setup, CellRenderer. If you give more details then we
might be able to help more.

Here is an example of why I need to get a Gtk::CellRenderer for a specific cell: I have a TreeView with 2 columns. When the user clicks in a cell with mousebutton1 I want to set the background color of the cell he clicked in to red;
class ModelColumns : public Gtk::TreeModel::ColumnRecord
ModelColumns()  {   add(m_col_a); add(m_col_b);   add(m_col_visible);  }
Gtk::TreeModelColumn<string> m_col_a;
Gtk::TreeModelColumn<double> m_col_b;
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);

// Append the columns
m_TreeView.append_column("A", m_Columns.m_col_a);
m_TreeView.append_column("B", m_Columns.m_col_b);

// I register to receive a callback for button press events in the treeview.
m_TreeView.signal_button_press_event().connect( SigC::slot(*this, &ExampleWindow::on_m_TreeView_button_press), false );

bool ExampleWindow::on_m_TreeView_button_press(GdkEventButton *eventbutton)
Gtk::TreeModel::Path  path;
Gtk::TreeViewColumn*  column;
int cell_x;
int cell_y;
Gtk::TreeModel::Row row;

// catch mouse button1 clicks
switch (eventbutton->type)
    if ( eventbutton->button == 1)
if (m_TreeView.get_path_at_pos(eventbutton->x, eventbutton->y, path, column, cell_x, cell_y )) { // Get the row number int row_num = *path.get_indices().begin(); row = *( m_refTreeModel->children[row_num - 1]);
           // Get the column number
           int column_number = -1;
           while (column != treeView->get_column(column_number))

// So at this point I have a Gtk::TreeViewColumn, a column number, a Gtk::TreeModel::Row and a row number // I want to get at the CellRendererText * for that cell so I can do something like this :

Gtk::CellRendererText* pRenderer = (I don't know how to do this .......but it should point to the cellrenderer for the cell the user clicked in)
         Gdk::Color col("red");
 return false;

Thanks !

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