Re: Freeze a treeview column
- From: "muppet" <scott asofyet org>
- To: gtk-perl-list gnome org
- Subject: Re: Freeze a treeview column
- Date: Fri, 16 Apr 2004 12:39:48 -0400 (EDT)
Jan Hudec said:
You can do one of two things:
1) You can add the scrolled window to the right pane and the right view
right into it. And then just bind the left view to the same
adjustments. So the packing goes:
- Paned
- left TreeView
- ScrolledWindow
- right TreeView
and then you bind left TreeView to proper adjustments (the right is
already bound).
This is just a minor change of the original example i posted. A very
important bit (that i missed earlier when i decided that it wouldn't work --
thanks for pointing out my idiocy ;-) is that you need to tell the first
treeview (the one not going into a scrolled window) not to request enough
height to display all of its rows.
use strict;
use Gtk2 -init;
my $model = Gtk2::ListStore->new (('Glib::Int')x16);
for (0..99) {
$model->set ($model->append,
0, $_,
map { ($_, int (255 * rand())) } 1..$model->get_n_columns-1
);
}
my $window = Gtk2::Window->new;
my $paned = Gtk2::HPaned->new;
my $view1 = Gtk2::TreeView->new ($model);
my $view2 = Gtk2::TreeView->new ($model);
# left view, showing only the first column
my $col = Gtk2::TreeViewColumn->new_with_attributes
('Col 0', Gtk2::CellRendererText->new, text => 0);
$view1->append_column ($col);
# right view, showing the remaining columns
for (1..$model->get_n_columns-1) {
$col = Gtk2::TreeViewColumn->new_with_attributes
("Col $_", Gtk2::CellRendererText->new, text => $_);
$view2->append_column ($col);
}
# place the first view in the left pane by itself.
$paned->add1 ($view1);
# VERY IMPORTANT - tell the view not to try to display all of its rows.
# we set the vertical size request very small, and it will fill up the
# available space when we set the default size of the window.
$view1->set_size_request (-1, 10);
# the second view goes in the right, inside a scrolled window.
my $scroll2 = Gtk2::ScrolledWindow->new;
$scroll2->add ($view2);
$paned->add2 ($scroll2);
# linked scrolling
$view1->set (vadjustment => $scroll2->get_vadjustment);
# linked selection
$view1->get_selection->signal_connect (changed => \&sync_selection, $view2);
$view2->get_selection->signal_connect (changed => \&sync_selection, $view1);
sub sync_selection {
my ($selection, $otherview) = @_;
$otherview->get_selection->select_iter
(scalar $selection->get_selected);
}
$window->add ($paned);
$window->set_default_size (400, 400);
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->show_all;
Gtk2->main;
--
muppet <scott at asofyet dot org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]