The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Gtk2::Ex::CellRendererWrappedText - Widget for displaying and editing multi-line text entries in a TreeView


 use Gtk2::Ex::CellRendererWrappedText;
 $treeview->new( $model );
 $cell = Gtk2::CellRender

 $cell = Gtk2::Ex::CellRendererWrappedText->new;
 $cell->set( editable => 1 );
 $cell->set( wrap_mode => 'word' );
 $cell->set( wrap_width => 400 );
 $cell->signal_connect (edited => sub {
                my ($cell, $text_path, $new_text, $model) = @_;
                my $path = Gtk2::TreePath->new_from_string ($text_path);
                my $iter = $model->get_iter ($path);
                $model->set ($iter, 1, $new_text);
        }, $model);

 $column = Gtk2::TreeViewColumn->new_with_attributes( 'Wrapped', $cell, text => 1 );
 $column->set_resizable( 1 );
 $view->append_column ($column);


+-- Glib::InitiallyUnowned
....+-- Gtk2::Object
........+-- Gtk2::CellRenderer
............+-- Gtk2::CellRendererText
................+ Gtk2::Ex::CellRendererWrappedText


Gtk2::Ex::CellRendererWrappedText is a Gtk2::CellRendererText that automatically updates the wrap-width of the of the renderer when it is resized so that it always expands or shrinks to the avaialble area.

This module also handles editing of strings that span multiple lines by using a TextView instead of an Entry as CellRendererText does.

Pressing <Esc> whil in edit mode cancels the edit. Pressing <Enter> moves to the next line. Pressing <Ctrl+Enter> or focusing out of the renderer finishes editing and emits the 'edited' signal.


Using this module produces this warning:

    GLib-GObject-CRITICAL **: Object class Gtk2__Ex__CellRendererWrappedText__TextView
    doesn't implement property 'editing-canceled' from interface 'GtkCellEditable' at ...

This is only a warning, and a known issue with Gtk+ and the Gtk2-Perl bindings that will not affect behaviour of the widget.

See this post for more information:


Jeffrey Ray Hallock <jeffrey.hallock at gmail dot com>

Some code adapted from Muppet's script included in the Gtk2 examples directory.


Copyright (c) 2010-2012 Jeffrey Ray Hallock.

    This is free software, licensed under:

    The Artistic License 2.0 (GPL Compatible)