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

RE: setting color of some of the rows in a TreeView



Hi All,
I have a similar urgent requirement in Perl-Gtk.( I currently am not in a position to move to Gtk2).
Is there a similar setting of colors possible for the tree items in a Tree View in Perl-Gtk?
Thanks In Advance
Ashwin




-----Original Message-----
From: gtk-perl-list-bounces gnome org on behalf of Bostjan Spetic
Sent: Fri 4/22/2005 1:39 PM
To: GTK2-Perl List
Subject: Re: setting color of some of the rows in a TreeView
 
On Fri, 22 Apr 2005 09:51:45 +0300, Gabor Szabo <szabgab gmail com> wrote:

> I have been fighting with for some time now but I could not find the answer.
> How can I set the color of some of the rows in a TreeView ?
> I don't mean the alternating colors, I have a few that I would like to
> stand out.

i do it with custom data function for cell renderer:

	my $clist = Gtk2::ListStore->new(@types);
	$tv->set_rules_hint(1);
	$tv->set_model($clist);
	for (my $i = 0; $i < @{$order}; $i++) {
		my $renderer = Gtk2::CellRendererText->new ;
			$renderer->set('editable' => TRUE);
			$renderer->set('mode' => 'editable');
    			$renderer->signal_connect ('edited' => sub {
  	           my ($cell,$text_path,$new_text,$i) = @_;
  				  my $tree = $tv->get_model;
  				  my $iter = $tree->get_iter_from_string($text_path);
				  if (defined $iter) {
  					   #my $old_text = $tree->get($iter,$i);
  						$tree->set($iter,$i,$new_text);
  				  }
   			 	},$i);	
		my $title = ${$order}[$i];
		my $cl = Gtk2::TreeViewColumn->new_with_attributes('',$renderer,'text' => $i);
		$tv->append_column($cl);
		$cl->set_clickable(1);
		$cl->set_resizable(0);
		$cl->set_sort_column_id($i);
		$cl->set_title($title);
		$tv->get_model->set_sort_func($i,\&sort_by_color,$i);
# ----->
		$cl->set_cell_data_func($renderer, sub {
	         my ($column, $cell, $model, $iter, $title) = @_;
	         my $color = 'white';
				my ($cursor) = $tv->get_cursor;
				my $entry = $entries{$title};
				if (!defined $entry) { $entry = ""; }
				my $text = $cell->get('text');
				if ((defined $entry) and (defined $text) and ($text ne "")) {
					if ($text =~ /$entry/i) {
						$color = 'orange';
					}
				}
	         $cell->set (background => $color);
     		}, $title);
# <------
	}
	
regards, bostjan

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list




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