Reputation: 3272
I use TreeView and ListStore to show a GUI table. How can I set color a defined row? Are there any samples how to do it? With google I've found an example only for SimpleList, but I need it for ListStore.
Upvotes: 2
Views: 1034
Reputation: 3272
There are two ways to set color on a TreeView. The first is: Set a column where color will be keep and then use method of TreeViewColumn "set_attributes" to set color of a cell renderer.
my $list_store = Gtk2::ListStore("Glib::String", "Glib::String"); # keep one note and color
my $tree_view = Gtk2::TreeView->new($list_store);
my $col = Gtk2::TreeViewColumn->new;
my $rend = Gtk2::CellRendererText->new;
$col->pack_start($rend, TRUE);
$col->set_attributes($rend,'text' => $i++, 'background' => 1,);
$tree_view->append_column($col);
And the second way is: Do not use an additional column to keep a color but use method set_cell_data_func of TreeViewColumn:
$col->set_cell_data_func($rend, sub {
my ($column, $cell, $model, $iter) = @_;
if ($model->get($iter, 0) eq 'Good') {
print "Red\n";
$cell->set('background' => 'red');
} else {
$cell->set('background' => 'white');
}
});
Upvotes: 1