Re: Freeze a treeview column

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

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.

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);

# 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) = @_;
                              (scalar $selection->get_selected);

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

muppet <scott at asofyet dot org>
gtk-perl-list mailing list
gtk-perl-list gnome org

                                                 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]