Reputation: 1521
I have a button that is displayed with an image.
I would like to show some text when the mouse is hovering on top of it (like any desktop icon would do, or even images on HTML pages).
I am not sure if there is any facility to do that, I could not find any by looking at the GtkButton class.
Does anyone please know how I can set some text labels when the mouse is hovering on top of a button please?
Thank you very much!
Upvotes: 2
Views: 2299
Reputation: 11405
You are probably looking for GtkTooltip
. There are simple APIs as part of GtkWidget
to set & get tool tip. Use gtk_widget_set_tooltip_text
to add simple text as tips for the widget or gtk_widget_set_tooltip_markup
for adding text with Pango markup language. Here is a sample code for your reference:
#include <gtk/gtk.h>
int main(void)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button0;
GtkWidget *button1;
gtk_init(NULL, NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
button0 = gtk_button_new_with_label("Normal tip");
gtk_widget_set_tooltip_text(button0, "Simple tip");
button1 = gtk_button_new_with_label("Markup tip");
gtk_widget_set_tooltip_markup(button1, "This is <b>bold</b> & this is <i>italics</i>");
gtk_box_pack_start(GTK_BOX(vbox), button0, 1, 1, 1);
gtk_box_pack_start(GTK_BOX(vbox), button1, 1, 1, 1);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Hope this helps!
Upvotes: 6