如何在Gtk2 :: SimpleList中捕获布尔切换复选框的切换?
我理解复选框本身是一个Gtk2 :: CellRendererToggle,它会发出toggled
信号,但是如何访问它并设置信号处理程序?
如何在SimpleList小部件中捕获数据编辑的事件?
use Glib qw(TRUE FALSE);
use Gtk2 '-init';
use Gtk2::SimpleList;
my $slist = Gtk2::SimpleList->new(
'Bool Field' => 'bool',
'Text Field' => 'text'
);
$slist->set_column_editable(1, TRUE);
@{$slist->{data}} = (
[ TRUE, 'text' ],
[ FALSE, 'more text' ]
);
my $window = Gtk2::Window->new;
$window->set_border_width(8);
$window->signal_connect(destroy => sub { exit(0); });
$window->add($slist);
$window->show_all;
Gtk2->main;
答案 0 :(得分:0)
在深入了解SimpleList.pm后,我想出了下面的代码,它似乎有效。但这不是很直观。
# bool column
my $col = $slist->get_column(0);
my $r = $col->get_cell_renderers;
$r->signal_connect(toggled => sub {
my ($widget, $value, $args) = @_;
print "checkbox toggled to $value\n";
});
# text column
($slist->get_column(1))->get_cell_renderers->signal_connect(
edited => sub {
my ($widget, $text_path, $new_text, $args) = @_;
print "new text is $new_text\n";
}
);