我尝试在一个
当我以这种方式创建颜色时,我会得到相同的错误:
Gtk3::TreeViewColumn
中设置背景颜色:my $red = Gtk3::Gdk::RGBA->new(1, 0.8, 0.8, 1);
my $renderer = Gtk3::CellRendererText->new;
my $column = Gtk3::TreeViewColumn->new_with_attributes
($c, $renderer, text => $n, background => $red);
但是我遇到了以下错误:
Gtk-CRITICAL **: 09:54:09.834: gtk_list_store_get_value: assertion 'column < priv->n_columns' failed
GLib-GObject-CRITICAL **: g_value_transform: assertion 'G_IS_VALUE (src_value)' failed at /usr/share/perl5/Gtk3.pm line 568.
GLib-GObject-WARNING **: unable to set property 'background' of type 'gchararray' from value of type '(null)' at /usr/share/perl5/Gtk3.pm line 568.
当我以这种方式创建颜色时,我会得到相同的错误:
my $red2 = Gtk3::Gdk::RGBA::parse ('#FF0000');
有人能解释如何设置背景色吗?
完整示例:
#! /usr/bin/perl
use strict;
use warnings;
use utf8;
use Gtk3 -init;
use Glib 'TRUE', 'FALSE';
my @COLUMNS = (
'a',
'b',
'c');
my $red = Gtk3::Gdk::RGBA->new(1, 0, 0, 1);
my $red2 = Gtk3::Gdk::RGBA::parse ('#F00');
my $window = Gtk3::Window->new ('toplevel');
my $notebook = Gtk3::Notebook->new;
$window->add($notebook);
my $sw = Gtk3::ScrolledWindow->new (undef, undef);
$notebook->append_page ($sw, Gtk3::Label->new ("tab"));
my $model = Gtk3::ListStore->new (('Glib::String') x scalar @COLUMNS);
my $row = $model->append ();
$model->set ($row,
0, "a",
1, "b",
2, "c");
my $treeview = Gtk3::TreeView->new($model);
$sw->add($treeview);
while (my ($n, $c) = each @COLUMNS) {
my $renderer = Gtk3::CellRendererText->new;
my $column = Gtk3::TreeViewColumn->new_with_attributes
($c, $renderer, text => $n, background => $red);
$treeview->append_column($column);
}
$window->show_all;
Gtk3->main();