Re: Multiple cell renderers within one cell



On Monday, March 29, 2004, at 05:01 PM, Brian wrote:

According to the Gtk+2.0 Tree View Tutorial, it's possible to have multiple cell renderers for a given cell.  However, the author of this excellant paper stops short of showing actual code to do this.  Anyone have some code to show using more than one cell-renderer within  a given cell?

contrived, but it works:

#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib ':constants';

my $model = Gtk2::ListStore->new (qw(Glib::Int Glib::String));
$model->set ($model->append, 0, 0, 1, 'gtk-open');
$model->set ($model->append, 0, 1, 1, 'gtk-close');
$model->set ($model->append, 0, 2, 1, 'gtk-ok');
$model->set ($model->append, 0, 3, 1, 'gtk-cancel');

my $treeview = Gtk2::TreeView->new ($model);

# a column with a toggle renderer and a text renderer
my $numcol = Gtk2::TreeViewColumn->new;
$numcol->set_title ("number");

my $cell = Gtk2::CellRendererToggle->new;
$numcol->pack_start ($cell, FALSE);
$numcol->add_attribute ($cell, active => 0);

$cell = Gtk2::CellRendererText->new;
$numcol->pack_start ($cell, TRUE);
$numcol->add_attribute ($cell, text => 0);

$treeview->append_column ($numcol);


# a column with a pixbuf renderer and a text renderer
my $stockcol = Gtk2::TreeViewColumn->new;
$stockcol->set_title ('stock id');

$cell = Gtk2::CellRendererPixbuf->new;
$stockcol->pack_start ($cell, FALSE);
$stockcol->add_attribute ($cell, stock_id => 1);

$cell = Gtk2::CellRendererText->new;
$stockcol->pack_start ($cell, TRUE);
$stockcol->add_attribute ($cell, text => 1);

$treeview->append_column ($stockcol);


my $window = Gtk2::Window->new;
$window->add ($treeview);
$window->signal_connect (delete_event => sub { Gtk2->main_quit });
$window->show_all;
Gtk2->main;


--
elysse (pregnant): are your hands cold?
me: uh, i suppose so.
elysse: will you put them on me?




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