[Glade-users] signals with GtkOptionMenu's

Matt wrote:

        Hey all,

        I have spent quite a few hours trying to figure this out on my own
with no luck, so I hope you will forgive me if this is a frequently asked
question ...

Yes, it is!

        I am creating GtkOptionMenu's with glade and I would like to
detect which menu option is currently selected.  The only way I have
successfully been able to do this is to attach a signal to each menu
option which calls a signal handler and states which menu option has been

4.7 How do I get the value of a GtkOptionMenu?

Call gtk_menu_get_active() with the GtkOptionMenu's menu to get the currently
selected menu item. You can use g_list_index() to find its index in the menu:

on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
  GtkWidget *option_menu, *menu, *active_item;
  gint active_index;

  option_menu = lookup_widget (GTK_WIDGET (button), "optionmenu1");
  menu = GTK_OPTION_MENU (option_menu)->menu;
  active_item = gtk_menu_get_active (GTK_MENU (menu));
  active_index = g_list_index (GTK_MENU_SHELL (menu)->children, active_item);

  g_print ("Active index: %i\n", active_index);

Question 4.8 may also be useful. See http://glade.gnome.org for the FAQ.


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