Re: Gtk::TreeView cell background color
- From: Jonathon Jongsma <jonathon jongsma gmail com>
- To: Jason Burchfield <jason burchfield cas-inc com>
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: Gtk::TreeView cell background color
- Date: Tue, 29 Nov 2005 14:14:54 -0600
On 11/29/05, Jason Burchfield <jason burchfield cas-inc com> wrote:
> When I add a Gtk::TreeModelColumn<bool>, which uses a
> Gtk::CellRendererToggle, to a Gtk::TreeView and try to change the cell
> color I get a seg fault.
> Is this a bug or am I doing something wrong. All other columns work...
I'm not an expert, but I did successfully get a treeview to use
different background colors as follows. I'll show you how I did it in
just a second, but first note that if you're just trying to alternate
colors, you may want to take a look at the
Gtk::TreeView::set_rules_hint() function
(http://gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeView.html#a115).
Anyway, this is how I did it. I'm not sure it's the best way, but it
seemed to work. I derived my own class from a Gtk::TreeView (called
BookmarkList) and added a single column to it that contained a string
representation of a color (e.g. #FFFFFF). This string was supposed to
be used to set the background color of the cell. The constructor was
as follows:
BookmarkList::BookmarkList(void)
: m_refListStore(Gtk::ListStore::create(m_columns))
{
set_model(m_refListStore);
// Display string representation of the color
append_column("Favorites", m_columns.m_colText);
// set a function to call when the data for a particular value is
// set so that we can use the information to set the background
// color of the cell
get_column(0)->set_cell_data_func(*get_column_cell_renderer(0),
sigc::mem_fun(*this, &BookmarkList::set_cell_background));
// display column headers
set_headers_visible(true);
}
The important part being the set_cell_data_func call. This function
specifies a callback function that will set the color for each cell.
The function was defined as follows:
void BookmarkList::set_cell_background(Gtk::CellRenderer* cell,
const Gtk::TreeModel::iterator& iter)
{
// set the background color equal to the value of the hexstring
cell->property_cell_background() = (*iter)[m_columns.m_colText];
}
Hope that helps.
Jonathon
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]