1
我使用TreeView和ListStore來顯示一個GUI表。我如何設置顏色定義的行?有沒有樣品怎麼做?與谷歌我已經找到了一個SimpleList的例子,但我需要它的ListStore。如何在Gtk2 :: TreeView Perl中設置一行的顏色?
我使用TreeView和ListStore來顯示一個GUI表。我如何設置顏色定義的行?有沒有樣品怎麼做?與谷歌我已經找到了一個SimpleList的例子,但我需要它的ListStore。如何在Gtk2 :: TreeView Perl中設置一行的顏色?
有兩種方法可以在TreeView上設置顏色。 第一個是: 設置將保留顏色的列,然後使用TreeViewColumn「set_attributes」的方法設置單元格渲染器的顏色。
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);
而第二個方法是: 不要使用其他列,以保持TreeViewColumn的顏色,但使用方法set_cell_data_func:
$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');
}
});