Previous Next Contents

7. The Tooltips Widget

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 GDK.

Some widgets (such as the label) will not work with tooltips.

The first call you will use to create a new tooltip. You only need to do this once in a given function. The GtkTooltip 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_tips   (GtkTooltips *tooltips,
                              GtkWidget   *widget,
                              gchar       *tips_text);

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.

Here's a short example:

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

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

void gtk_tooltips_destroy    (GtkTooltips *tooltips);

Destroy the created tooltips.

void gtk_tooltips_enable     (GtkTooltips *tooltips);

Enable a disabled set of tooltips.

void gtk_tooltips_disable    (GtkTooltips *tooltips);

Disable an enabled set of tooltips.

void gtk_tooltips_set_delay  (GtkTooltips *tooltips,
                              gint         delay);
Sets how many milliseconds you have to hold you pointer over the widget before the tooltip will pop up. The default is 1000 milliseconds or 1 second.

void      gtk_tooltips_set_tips (GtkTooltips *tooltips,
                                 GtkWidget   *widget,
                                 gchar    *tips_text);

Change the tooltip text of an already created tooltip.

void gtk_tooltips_set_colors (GtkTooltips *tooltips,
                              GdkColor    *background,
                              GdkColor    *foreground);

Set the foreground and background color of the tooltips. Again, I have no idea how to specify the colors.

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


Previous Next Contents