Re: Colorize rows in SimpleList ?
- From: Emmanuele Bassi <bassi-e libero it>
- To: gtk-perl-list gnome org
- Subject: Re: Colorize rows in SimpleList ?
- Date: Mon, 15 Dec 2003 18:35:27 +0100
* John McDermott <jjm jkintl com>:
Can I set colors on individual rows in a SimpleList? I want some red,
some green, etc. If I can, how do I go about it?
Just create a cell_data_func, and change the "background" and
"foreground" properties of the associated cellrenderer. E.g.:
use constant COLOR_RED => 0;
use constant COLOR_GREEN => 1;
$treecolumn->set_cell_data_func(sub {
my ($column, $renderer, $model, $iter) = @_;
# you could fetch the data from an invisible column,
# whose value is handled programmatically; or you may
# act on the content of a visible column, although I do
# not recommend it. The rationale for using the former
# approach is: a cell_data_func should be as fast as
# possible, since it will be called on every idle cycle.
my $color = $model->get($iter, COLUMN_COLOR);
if (COLOR_RED eq $color) {
$renderer->set_property(background => 'red');
}
elseif (COLOR_GREEN eq $color) {
$renderer->set_property(background => 'green');
}
});
See: Gtk2::TreeViewColumn and Gtk2::CellRendererText.
[Note that the 'background' and 'foreground' properties are available
for Gtk2::CellRendererText only.]
Regards,
Emmanuele.
--
Emmanuele Bassi (Zefram) [ http://www.emmanuelebassi.net ]
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738 08BD 8ECC DB8F A432 0FF4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]