Re: Can't set values in ListStore/TreeView



2009/3/13 Rosalind Mitchell <rcmitchell gmail com>:
I have been working on a Âmodest application using Perl-Gtk2 and have stumbled
on a problem with populating lists. ÂI can set up a TreeView quite happily,
and a model (ListStore for simplicity) to plug into it. ÂI can append lines to
the ListStore and they show up nicely in the TreeView. ÂWhat I haven't been
able to do, despite following what documentation I've turned up with Google,
is to populate the list so that it shows up on screen. ÂI must be doing
something wrong, or leaving something out, but what?

Stripped-down sample code, which exhibits this behaviour, is below. ÂCan
anybody help?

------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

use warnings;
use strict;

use Glib qw [TRUE FALSE];
use Gtk2 '-init';

my $mw = Gtk2::Window->new;
$mw->signal_connect(destroy => sub{Gtk2->main_quit});

my $liststore = Gtk2::ListStore->new('Glib::String');
my $treeview = Gtk2::TreeView->new($liststore);

my $render = Gtk2::CellRendererText->new;
my $col = Gtk2::TreeViewColumn->new_with_attributes("Name", $render);
$treeview->append_column($col);

$mw->add($treeview);

my @list = qw [Hugh Pugh Barney McGrew Cuthbert Dibble Grubb];
foreach (@list) {
   Âmy $iter = $liststore->append;
   Â$liststore->set($iter, 0, $_);
}

$mw->show_all;
Gtk2->main;
------------------------------------------------------------------------------------------------------------------------


Thanks

Rosie

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


Hi.

The values are not shown because you don't connect "text" property of
the renderer to any ListStore column. Try replacing this line:

my $col = Gtk2::TreeViewColumn->new_with_attributes("Name", $render);

with

my $col = Gtk2::TreeViewColumn->new_with_attributes("Name", $render, "text", 0);

-- 
Tadej BorovÅak
tadeboro gmail com
tadej borovsak gmail com



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