Tooltips can't be set for menubar's top level menuitem.
- From: "DC A" <adc4444 hotmail com>
- To: gtk-list gnome org
- Subject: Tooltips can't be set for menubar's top level menuitem.
- Date: Thu, 03 Nov 2005 20:18:55 +0000
Hi,
I'm reading a book Sam's teach yourself Gtk+ programming and trying to set
tooltips for menubar's toplevel menuitem which in this case is file_item.
the book states that I can set tooltips with gtk_tooltips_set_tip() function
without the use of GtkTipsQuery. I did exactly what it said and it works
only for menuitem that are enlisted in submenu not for the toplevel menuitem
in menuabar. I checked the api and it said "Tooltips can only be set on
widgets which have their own X window and receive enter and leave events. To
check if a widget has its own window use GTK_WIDGET_NO_WINDOW()." I tested
whether file_item(toplevel menuitem) and exit_item(Submenu's menuitem) have
their own window with GTK_WINDOW_NO_WINDOW macro and it tested TRUE for both
of them and still tooltips can be set only for submenu's menuitem and not
for menubar's top level menuitem. I'm bit confused here. Anyone know what
should I do or what am I doin' wrong? Thanks.
Note: The code I used is listed below.
#include <gtk/gtk.h>
#define NONHOMOGENEOUS FALSE
#define NO_SPACING 0
gboolean delete_handler(GtkWidget *widget, GdkEvent *event, gpointer
user_data)
{
return FALSE;
}
void destroy_handler (GtkObject *object, gpointer user_data)
{
gtk_main_quit();
}
int main(int argc, char *argv[])
{
GtkWidget *top_window, *vbox, *label;
GtkWidget *menu_bar, *file_item, *file_menu, *separator, *exit_item;
GtkTooltips *tooltips;
/* 1)Initialize the environement*/
gtk_init(&argc, &argv);
/* 2)Create widgets and show attributes*/
top_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
vbox = gtk_vbox_new(NONHOMOGENEOUS, NO_SPACING);
label = gtk_label_new("GTK+ is fun.");
menu_bar = gtk_menu_bar_new();
file_item = gtk_menu_item_new_with_label("File");
file_menu = gtk_menu_new();
separator = gtk_menu_item_new();
exit_item = gtk_menu_item_new_with_label("Exit");
tooltips = gtk_tooltips_new();
/* 2b)Show attributes */
gtk_window_set_title(GTK_WINDOW (top_window), "Test");
gtk_widget_set_size_request(label, 200, 200);
/* 3)Register siganls */
g_signal_connect(G_OBJECT(top_window), "delete-event",
G_CALLBACK(delete_handler), NULL);
g_signal_connect(G_OBJECT(top_window), "destroy",
G_CALLBACK(destroy_handler), NULL);
g_signal_connect(G_OBJECT(exit_item), "activate",
G_CALLBACK(destroy_handler), NULL);
/* 4)Create instance hierarchy*/
gtk_box_pack_start_defaults(GTK_BOX(vbox), menu_bar);
gtk_box_pack_start_defaults(GTK_BOX(vbox), label);
gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), file_item);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file_item), file_menu);
gtk_menu_append(GTK_MENU(file_menu), separator);
gtk_menu_append(GTK_MENU(file_menu), exit_item);
gtk_container_add(GTK_CONTAINER(top_window), vbox);
/*5)Show widgets*/
gtk_widget_show(file_item);
gtk_widget_show(separator);
gtk_widget_show(exit_item);
gtk_widget_show(menu_bar);
gtk_widget_show(label);
gtk_widget_show(vbox);
gtk_widget_show(top_window);
gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), file_item, "Filetoshow",
NULL);
gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), exit_item, "Exit", NULL);
gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), label, "Exit", NULL);
/*6)Process signals*/
gtk_main();
/*7)Quitting*/
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]