Re: Freeze a treeview column



I modified the program from yesterday to implement the viewport idea, it works, but now the title columns get scrolled away :)

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);
my $vp1 = Gtk2::Viewport->new;
my $vp2 = Gtk2::Viewport->new;

# 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
$vp1->add($view1);
my $scroll1 = Gtk2::ScrolledWindow->new;


$paned->add1 ($vp1);

# linked scrolling
#my $scroll2 = Gtk2::ScrolledWindow->new (undef, $scroll1->get_vadjustment);

$vp2->add($view2);


$paned->add($vp2);
$scroll1->add_with_viewport($paned);



$window->add($scroll1);
$window->set_default_size (400, 400);
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->show_all;
Gtk2->main;



Jan Hudec wrote:

On Fri, Apr 16, 2004 at 10:22:17 -0400, muppet wrote:
Jan Hudec said:
On Thu, Apr 15, 2004 at 12:46:05 -0400, muppet wrote:
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.
IIRC it's packed like:

   +ScrolledWindow----+
   |+Viewport------+ ^|
   ||+the widget--+| v|
   |||            || S|
   |||            || c|
   |||            || r|
   |||            || o|
   |||            || l|
   ||+------------+| l|
   |+--------------+ V|
   |<HScrollBar---->  |
   +------------------+

And the scrolledwindow is just a 2x2 table, that shows/hides the
scrollbars acoording to difference between it's allocation and child's
requisition. It is possible to pack a viewport and scrollbars in
a normal table, except the scrollbars must always be visible.

Note: I am not actualy sure if ScrolledWindow uses Viewport internaly,
but I am sure a Viewport exists.
$scrolled_window->add_with_viewport ($child) won't buy you anything, because
a) the bottom scrollbar in the paned widget will not always be in view and b)
the TreeView is a natively scrolling widget, and using a viewport on it takes
a rather substantial performance hit, if i recall correctly.

I am talking about NOT using scrolled_window.

So, to do that with the proper scrollbars, you'll have to create your own
container widget with your own scrollbars and viewports, and use the
adjustments properly.  Getting that to work is something i don't know how to
do in five minutes, so forgive me if i don't include an example.

I think you don't have to write anything. Just pack it like this:

 +Table------------------------+
 |+Viewport 1--++Viewport 2--+^|
 ||+column 1--+||+the rest--+|V|
 |||          ||||          ||S|
 |||          ||||          ||c|
 |||          ||||          ||r|
 |||          ||||          ||o|
 |||          ||||          ||l|
 ||+----------+||+----------+|l|
 |+------------++------------+V|
 |              <HScrollBar==> |
 +-----------------------------+

And then bind the Adjustments to the viewports manualy.

This should work like ScrolledWindow with both policies set to always,
because all the scrolling functionality is in the viewport widget.

-------------------------------------------------------------------------------
                                                 Jan 'Bulb' Hudec <bulb ucw cz



--
Brian McAndrews
Archelon
bmcandrews efs-us com
312.788.6309





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