Re: Freeze a treeview column

On Fri, Apr 16, 2004 at 10:22:18 -0500, B McAndrews wrote:
hey, it worked! one problem though, I get this gtk message when  I call:

Gtk-WARNING **: gtk_scrolled_window_add(): cannot add non scrollable 
widget use gtk_scrolled_window_add_with_viewport() instead at 
./ line 82.

when I use: add_with_viewport instead, I'm back to the previous problem.

Because you can't add paned to scrolled_window. You can do one of two
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).
2) Use a table instead of scrolled_window and create the scrollbars
   manualy. So the packing goes:
    - Table
        - (0,1,0,1) Paned
            - left TreeView
            - right TreeView
        - (1,2,0,1) VScrollBar
        - (0,1,1,2) HScrollBar
   and you manualy _create_ and bind the adjustments everywhere.
   Or alternatively the packing may be just:
    - Table
        - (0,1,0,1) left TreeView
        - (1,2,0,1) right TreeView
        - (2,3,0,1) VScrollBar
        - (1,2,1,2) HScrollBar
   which will look nicer (you will only have the scrollbar under the
   scrolled part), but I am not sure how adjusting of the left view will
   work (actualy, it should work and look right).

Jan Hudec wrote:

On Fri, Apr 16, 2004 at 10:03:23 -0500, B McAndrews wrote:

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

Oh, man, of course, I am stupid!

Since TreeView has the scrolling support itself, just remove the
viewports and bind the adjustments directly to the TreeViews. The
TreeView itself also has ->set_vadjustment and ->set_hadjustment.

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())) }

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
my $scroll1 = Gtk2::ScrolledWindow->new;

$paned->add1 ($vp1);

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



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

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? 
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
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
so they will scroll together.  The trouble is that i don't know if 
possible to hide the scrollbar on the left pane without implementing 


IIRC it's packed like:

|+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, 
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 
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 
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:

|+Viewport 1--++Viewport 2--+^|
||+column 1--+||+the rest--+|V|
|||          ||||          ||S|
|||          ||||          ||c|
|||          ||||          ||r|
|||          ||||          ||o|
|||          ||||          ||l|
|              <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
bmcandrews efs-us com


                                             Jan 'Bulb' Hudec 
                                             <bulb ucw cz

Brian McAndrews
bmcandrews efs-us com

                                                 Jan 'Bulb' Hudec <bulb ucw cz>

Attachment: signature.asc
Description: Digital signature

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