17

I am trying to disable/inactive some of menu items under GTK+. I have created Menu In GTK+Glade under C, and on some external event I need to disable some of the menu options.

How can I do this?

Zach Johnson
  • 23,678
  • 6
  • 69
  • 86
User7723337
  • 11,857
  • 27
  • 101
  • 182

4 Answers4

15

You can use gtk_widget_set_sensitive(menuitem, true/false) to disable or enable the menu item widget.

Alternatively, if you used GtkUiManager and GtkAction to build the menu, use gtk_action_set_sensitive() instead.

axel_c
  • 6,557
  • 2
  • 28
  • 41
  • One more question.. how can i get to know that which menu item is selected... i have created menu in Glade... can i associate some Constant ID or Enum Constant to each menu items... so in call back i can bifurcate functionality depending on Constant. – User7723337 Nov 10 '09 at 11:51
  • You can either attach a different callback for each item's "activate" signal, or connect all the items to a single callback and check the first argument to see what item was selected. See http://library.gnome.org/devel/gtk/unstable/GtkMenuItem.html#GtkMenuItem-activate for details. – axel_c Nov 10 '09 at 11:57
4

Using:

gtk_widget_set_sensitive (menuitem,FALSE); // to gray-out
gtk_widget_set_sensitive (menuitem,TRUE); //to enable
spilver
  • 41
  • 1
2

Use with Vala + Gtk:

Gtk.Button play = new Gtk.Button.with_mnemonic("Play");
play.set_sensitive(false); // to gray-out
anlijudavid
  • 509
  • 6
  • 12
2

There is also a checkbox inside Glade to disable the menu item:

Select your menu item --> Common --> Widget Flags --> Uncheck "Sensitive"

enter image description here

manµ
  • 37
  • 5