[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Can't set values in ListStore/TreeView
- From: Tadej Borovšak <tadeboro gmail com>
- To: Rosalind Mitchell <rcm swimbarrow co uk>
- Cc: gtk-perl-list gnome org
- Subject: Re: Can't set values in ListStore/TreeView
- Date: Fri, 13 Mar 2009 16:19:45 +0100
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]