Re: Colour text in a Gtk2::CellRendererText in a Gtk2::TreeView
- From: Daniel Kasak <dkasak nusconsulting com au>
- To: gtk-perl-list gnome org
- Subject: Re: Colour text in a Gtk2::CellRendererText in a Gtk2::TreeView
- Date: Wed, 20 Oct 2004 14:40:20 +1000
muppet wrote:
On Oct 19, 2004, at 7:09 PM, Daniel Kasak wrote:
Some of my users want particular cells in a Gtk2::TreeView to be
highlighted in different colours depending on the data. eg if one
field has a flag set to 'parent' then another cell should be
formatted red, etc.
Is it possible to do this?
absolutely, but it's probably not as pretty as you'd like.
<snipped>
b) or, you can calculate the color on the fly in a cell data
function. this can get pretty processing-intensive, but is the only
way to handle some extremely dynamic data. the cell data func gets
called every time the column goes to draw a cell; its purpose is to
set the properties of the cell renderer, so the renderer draws the
right stuff.
$column = Gtk2::TreeViewColumn->new;
$renderer = Gtk2::CellRendererText->new;
$renderer->set (foreground_set => TRUE);
$column->pack_start ($renderer, TRUE);
$column->set_cell_data_func ($renderer, sub {
my ($column, $cell, $model, $iter) = @_;
# use an interesting and sophisticated algorithm to
# determine what text to display and what color it
# should be (a la spreadsheet cell functions, where
# the contents of the cell are not what is displayed)
my ($text, $color) = do_something_cool ($model, $iter);
$cell->set (text => $text,
foreground => $color);
});
<snipped>
Excellent :)
This works very well, and it's even quite fast ( at least for the couple
of hundred rows that I've given it ).
All of the colours I've tried so far have worked, but where is the list
of available colours?
The docs say:
'foreground' (string : writable)
Foreground color as a string
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au
Title: CanIt Vote for ID 118629
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]