Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Gtk3 TreeView

by renegadex (Beadle)
on Jul 02, 2012 at 02:48 UTC ( #979357=perlquestion: print w/replies, xml ) Need Help??

renegadex has asked for the wisdom of the Perl Monks concerning the following question:

hi perl monkies, I need help in creating a simple editable treeview. Back in Gtk2, I am using Gtk2::SimpleList. Now I am having a problem because the SimpleList was removed on the Gtk3.

Now I did my research and end up with this...

my $model = Gtk3::ListStore->new('Glib::String'); my $list = Gtk3::TreeView->new(); $list->set_model($model); my $cell = Gtk3::CellRendererText->new(); $cell->set('editable'=>1); my $column = Gtk3::TreeViewColumn->new_with_attributes('name',$cell,'t +ext',$i); $list->append_column($column);

The problem here is that if I added a new row and tries to edit the contents of it by double clicking and typing a new text after I press enter, the new text is not updated. So I did googling around and found this site.

http://python-gtk-3-tutorial.readthedocs.org/en/latest/cellrenderers.h +tml#cellrenderertext

It says that I need to update the liststore manually using the edited signal. Problem is that I can't seem to find a way to properly get the iterator of the row so that I could update the liststore manually by using:

$list->set($iter,0,'edited text here');

Please help. Thanks in Advance

Mabuhay Civil Engineers! :D

Replies are listed 'Best First'.
Re: Gtk3 TreeView
by zentara (Archbishop) on Jul 02, 2012 at 09:01 UTC
    It says that I need to update the liststore manually using the edited signal. Problem is that I can't seem to find a way

    This is from Gtk2 code, but should work on Gtk3.

    ..... .... #this will create a treeview, specify $tree_store as its model my $tree_view = Gtk2::TreeView->new($tree_store); #create a Gtk2::TreeViewColumn to add to $tree_view my $tree_column = Gtk2::TreeViewColumn->new(); $tree_column->set_title ("Select Something"); #for editing my $renderer = Gtk2::CellRendererText->new; $renderer->set_property('editable' => TRUE); $renderer->signal_connect (edited => \&cell_edited, $tree_store); ..... ..... sub cell_edited { my ($cell, $path_string, $new_text, $model) = @_; my $path = Gtk2::TreePath->new_from_string ($path_string); my $column = $cell->get_data ("column"); my $iter = $model->get_iter ($path); $model->set_value ($iter, $column, $new_text); }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Gtk3 TreeView
by Anonymous Monk on Jul 02, 2012 at 06:56 UTC

    a problem because the SimpleList was removed on the Gtk3.

    I wouldn't say it was removed exactly, anyway its a pure-perl module -- i'm not sure if it will run under gtk3 unmodified, but modification shouldn't be hard

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://979357]
Approved by ig
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2022-05-23 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?