http://www.perlmonks.org?node_id=682039

jettero has asked for the wisdom of the Perl Monks concerning the following question:

I'm enjoying Gtk2 quite a bit. I'm very new to it, but I've written some semi-fancy things with ease and it's just fun.

I got kinda stumped on tool tips though. I seem to be able to get them working everywhere except Gtk2::SimpleLists (which are really Gtk2::TreeViews).

It seems like I found most of the related topics, but I can't seem to get it to work. I want to add a tooltip to some of the rows of my simplelist.

# This is mostly their SmipleList example. They skipped warnings and +strict, # I only wrote the (non-working) tooltip stuff. use Data::Dumper; use Gtk2 '-init'; use Gtk2::SimpleList; use constant TRUE => 1; use constant FALSE => 0; $categories = Gtk2::SimpleList->new ('Categories' => 'text'); $categories->set_headers_visible(FALSE); @{$categories->{data}} = qw/Meat Beer Pizza Pasta Soda Juice Rabbitfoo +d/; $categories->set_has_tooltip(TRUE); # NOTE: thought this might help (n +ope) $path = Gtk2::TreePath->new_from_indices(0); $tip = new Gtk2::Tooltip; $tip->set_text("tooltip test"); $categories->set_tooltip_row($tip, $path); # NOTE: thought this might help, but I fail to see how it would # $categories->signal_connect( 'query-tooltip' => sub { # warn Dumper({args=>\@_, useless=>{tip=>$tip, path=>$path}}); # }); $window = Gtk2::Window->new; $window->set_title ('SimpleList examples'); $window->signal_connect (delete_event => sub {Gtk2->main_quit; TRUE}); $window->set_default_size (800,600); $window->add($categories); $window->show_all; Gtk2->main;

The documentation for both the C and the .pm is a little light (doxygen?), but I think I might need to do something with the signal? I believe it's been possible to do this since gtk 2.12.0, but I'm clearly missing something. There's some example code in the t/GtkTreeView.t that calls set_tooltip_row(), but it seems to be an example of testing something rather than an example of putting a tooltip on a row.

-Paul

Replies are listed 'Best First'.
Re: Gtk2 Treeview/Simplelist and set_tooltip_row()
by zentara (Archbishop) on Apr 22, 2008 at 18:24 UTC
    I googled for something, and it seems you can put a tooltip on a TreeView, see tooltips on treeview workaround . Since the perldoc for Gtk2::Ex::SimpleList says you can make a SimpleList from a Treeview (or derive the parent Treeview), you may be able to use that fact, to put the tooltips on the underlying TreeView. I guess one of the things on their to-do list, is to make tooltips more easily integrated into the TreeView widget. You might also ask on the gtk2-perl maillist.

    You can add a tooltip to the entire SimpleList widget, as shown below, so you might be able to somehow connect mouse motion to the nearest entry, and modify the tip-text dynamically.....but I'm just brainstorming.

    Also remember, that there is a difference between Gtk2::Tooltips and Gtk2::ToolTip.

    #!/usr/bin/perl use warnings; use strict; use Data::Dumper; use Gtk2 '-init'; use Gtk2::SimpleList; use constant TRUE => 1; use constant FALSE => 0; my $categories = Gtk2::SimpleList->new ('Categories' => 'text'); $categories->set_headers_visible(FALSE); @{$categories->{data}} = qw/Meat Beer Pizza Pasta Soda Juice Rabbitfoo +d/; $categories->set_has_tooltip(TRUE); # NOTE: thought this might help (n +ope) my $path = Gtk2::TreePath->new_from_indices(0); my $tooltips = Gtk2::Tooltips->new; #my $tip = Gtk2::Tooltip->new; $tooltips->set_tip($categories,"tooltip test", $path); $tooltips->enable; my $window = Gtk2::Window->new; $window->set_title ('SimpleList examples'); $window->signal_connect (delete_event => sub {Gtk2->main_quit; TRUE}); $window->set_default_size (800,600); $window->add($categories); $window->show_all; Gtk2->main;

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum

      Gtk2::Tooltips has been deprecaated, so I've been trying to stay away from them.

      I will ask about set_tooltip_row() on the mailing list. That's a good idea.

      -Paul

Re: Gtk2 Treeview/Simplelist and set_tooltip_row()
by zentara (Archbishop) on Apr 23, 2008 at 16:03 UTC
    Just for a quick hack check, I substituted in the code from the treeview tooltip example link from my previous response, derived the model from the $catagories SimpleList, and it seems to work( some minor problems to work out like popup position, columns not existing, and what to do with selected rows. Here it is if you care to work out the bugs, I'm lazy today. :-)
Re: Gtk2 Treeview/Simplelist and set_tooltip_row()
by muppet (Initiate) on Apr 29, 2008 at 04:19 UTC
    I answered you on the list. Quick version: when you turn on "has-tip", gtk+ will create the tooltip and ask you to set it up and whether to show it in the "query-tooltip" signal.
      Muppet, I was just going to link to that! Thanks again for your help. I think your code should also be here natively in a readmore code tag. Links have a way of aging out after a while.

      -Paul