<< Back to man.ChinaUnix.net

10.3. The Tooltips Object

These are the little text strings that pop up when you leave your pointer over a button or other widget for a few seconds. They are easy to use, so I will just explain them without giving an example. If you want to see some code, take a look at the testgtk.c program distributed with GTK.

Widgets that do not receive events (widgets that do not have their own window) will not work with tooltips.

The first call you will use creates a new tooltip. You only need to do this once for a set of tooltips as the GtkTooltips object this function returns can be used to create multiple tooltips.

GtkTooltips *gtk_tooltips_new( void );

Once you have created a new tooltip, and the widget you wish to use it on, simply use this call to set it:

void gtk_tooltips_set_tip( GtkTooltips *tooltips,
                           GtkWidget   *widget,
                           const gchar *tip_text,
                           const gchar *tip_private );

The first argument is the tooltip you've already created, followed by the widget you wish to have this tooltip pop up for, and the text you wish it to say. The last argument is a text string that can be used as an identifier when using GtkTipsQuery to implement context sensitive help. For now, you can set it to NULL.

Here's a short example:

GtkTooltips *tooltips;
GtkWidget *button;
.
.
.
tooltips = gtk_tooltips_new ();
button = gtk_button_new_with_label ("button 1");
.
.
.
gtk_tooltips_set_tip (tooltips, button, "This is button 1", NULL);

There are other calls that can be used with tooltips. I will just list them with a brief description of what they do.

void gtk_tooltips_enable( GtkTooltips *tooltips );

Enable a disabled set of tooltips.

void gtk_tooltips_disable( GtkTooltips *tooltips );

Disable an enabled set of tooltips.

And that's all the functions associated with tooltips. More than you'll ever want to know :-)