Re: Freeze a treeview column
- From: "muppet" <scott asofyet org>
- To: gtk-perl-list gnome org
- Subject: Re: Freeze a treeview column
- Date: Thu, 15 Apr 2004 12:46:05 -0400 (EDT)
B McAndrews said:
I'd like to "freeze" a tree view column (the first one) so that
horizontal scrolling will always show this column. Is this posible? Or
can I have some sort of split view?
ahem: The GtkTreeView is neither a sheet widget nor microsoft excel.
But what you *can* do is use a paned widget, with a single-column view in the
left pane and a multi-column view in the right pane. Both views can look at
the same model, and you can make them both use the same scrollbar adjustments
so they will scroll together. The trouble is that i don't know if it's
possible to hide the scrollbar on the left pane without implementing your own
container.
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);
for (1..$model->get_n_columns-1) {
$col = Gtk2::TreeViewColumn->new_with_attributes
("Col $_", Gtk2::CellRendererText->new, text => $_);
$view2->append_column ($col);
}
# right view, showing the remaining columns
my $scroll1 = Gtk2::ScrolledWindow->new;
$scroll1->add ($view1);
$scroll1->set_placement ('top-right'); # get the scrollbar out of the way
$paned->add1 ($scroll1);
$scroll1->set_policy ('never', 'automatic');
# linked scrolling
my $scroll2 = Gtk2::ScrolledWindow->new (undef, $scroll1->get_vadjustment);
$scroll2->add ($view2);
$paned->add2 ($scroll2);
# 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]