Re: Which column in a treeview did a user click in?




Daniel Kasak wrote:
Hi all.

I'd like to set up different things to happen when users click in ( or
at ) different columns in a treeview. At the moment, I'm connecting to
the treeview's button-press-event, but that doesn't let me figure out
which column the user was pointing at. Also, I'd like to be able to do
this both with columns that are editable, and columns that aren't editable.

I've found that a TreeViewColumn has a 'clicked' signal, but that's only
for the column *heading*.

Is this possible?


From Gtk2::TreeView(3pm):

   path = $tree_view->get_path_at_pos ($x, $y)

   (path, column, cell_x, cell_y) = $tree_view->get_path_at_pos ($x, $y)

       * $x (integer)
       * $y (integer)

       Finds the path at the point ($x, $y), relative to widget coordi-
       nates. That is, $x and $y are relative to an event?s coordinates.
       $x and $y must come from an event on the $tree_view only where
       "$event->window == $tree_view->get_bin_window". It is primarily for
       things like popup menus.  In scalar context, returns the
       Gtk2::TreePath, in array context, adds the Gtk2::TreeViewColumn,
       and $x and $y translated to be relative to the cell.  This function
       is only meaningful if $tree_view is realized.


So, something like

    $treeview->signal_connect (button_press_event => sub {
            my ($treeview, $event) = @_;
            if ($event->window == $treeview->get_bin_window) {
                # user clicked in the treeview proper, let's find
                # out exact-i-cally where:
                my ($path, $column, $cell_x, $cell_y) =
                    $treeview->get_path_at_pos ($event->x, $event->y);
                # $path is the Gtk2::TreePath of the row of the click
                # $column is the Gtk2::TreeViewColumn of the click
                # $cell_x, $cell_y are the location within the
                # cell of the click.
                do_stuff (...);
            }
    });



-- 
muppet <scott at asofyet dot org>




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