Re: How to bring up tooltip text for certain words in a GTK textview?

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

 



Richard & Tadej
Many thanks!

Here is what I did to make it kind of work:

 GtkWidget * e = gtk_text_view_new ( ) ;
 ...
 g_signal_connect ( G_OBJECT (e) , "query-tooltip" ,
                    G_CALLBACK (querytooltipcb) , NULL ) ;
 gtk_widget_set_has_tooltip ( e , true ) ;
 
with experimental callback:

static int counter=0;
static gboolean querytooltipcb (GtkWidget * w,
                                gint x,  gint y,
                                gboolean    keyboard_mode,
                                GtkTooltip *tooltip,
                                gpointer user_data )
   {
  printf ( "querytooltip(%d): x=%d y=%d kbm=%d  tip=%d\n" ,
           counter , x , y , keyboard_mode ? 1 : 0, (int)tooltip ) ;
   char text [ 400 ] ;
   sprintf ( text , Hello #%d (%d,%d)\nSecond line.\nThird line.\n" ,
             counter , x , y ) ;
   gtk_tooltip_set_text ( tooltip, text );
  counter++;
   return TRUE ;
   }

querytooltipcb is called while the mouse moves. I expected it to be
called only when the cursor has been steady for a short period of
time. When the mouse stops the tooltip text appears.
Then while the mouse is moved again querytooltipcb is called, but
the the tooltip remains in the same position (text is changed by
the callback to show call # and x,y). When I stop moving the mouse
the tooltip still remains. Clicking anywhere on the screen makes
it disappear.

I would like the tooltip to disappear when the mouse has moved
sufficiently far away from it. That would make it nicer for the
user who can sniff around on the screen from one technical
phrase to another without having to make the old tooltip disappear.
The gtk_tooltip_set_tip_area(tooltip, &rect) may solve this,
but I don't know how to use it. By the way, the codeblocks IDE
behaves like this when I let the cursor hover in the source text.

Finally, is there a way to change background colour of a tooltip area?

Regards
Ken





--- On Thu, 20/5/10, Tadej Borovšak <tadeboro@xxxxxxxxx> wrote:

From: Tadej Borovšak <tadeboro@xxxxxxxxx>
Subject: Re: How to bring up tooltip text for certain words in a GTK textview?
To: "richard boaz" <ivor.boaz@xxxxxxxxx>
Cc: "Ken Resander" <kresander@xxxxxxxxx>, gtk-list@xxxxxxxxx
Date: Thursday, 20 May, 2010, 2:23 AM

Hi.

General flow is correct, but GTK+ does offer some functionality that
may come handy in your case. (I'm commenting in a rather strange
succession because Richard top-posted his reply).

> unless gtk is now providing direct access to tooltip style pop-ups, you must create it yourself

GTK+ does offer access to tooltips in various ways: you can simply set
text or markup; you can insert custom content into tooltip; or you can
create your own window and present it as tooltip.

> meaning that you must create and manage your own borderless top-level window

This is not needed anymore.

> whose location must be explicitly specified to be placed onto the screen
> calculation of the window location coordinates must access the root-window where to the tooltip is to be located on top of, and
> since you don't have access to the size of the WM's borders on the root window, a little "guessing" as to the WM's size must be taken into account

If you connect to GtkWidget::query-tooltip signal, coordinates are
already provided, so I think most of this stuff is not needed now.

>> A textview shows help text with many 'technical' words that users may not know or remember. I would like a tooltip text with a short explanation to pop up when a user hovers the cursor over a technical phrase. There is a lookup table from technical phrases to explanations. I am thinking about using the mouse move event to get x,y then getting the technical phrase from x,y, then looking up the explanation and outputting the tooltip text.

Don't use movement events to monitor your position. Simply set text
view's "has-tooltip" property to "TRUE" and connect handler to
"query-tooltip" signal. Use coordinates provided by callback to find
the word that cursor hovers over and then do the lookup. I think
things should be relatively simple.

Tadej


--
Tadej Borovšak
tadeboro.blogspot.com
tadeboro@xxxxxxxxx
tadej.borovsak@xxxxxxxxx

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux