How to disable/inactive some of the GtkMenu Items
Asked Answered
B

4

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?

Bethought answered 10/11, 2009 at 11:9 Comment(0)
U
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.

Unhinge answered 10/11, 2009 at 11:27 Comment(2)
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.Bethought
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 library.gnome.org/devel/gtk/unstable/… for details.Unhinge
E
4

Using:

gtk_widget_set_sensitive (menuitem,FALSE); // to gray-out
gtk_widget_set_sensitive (menuitem,TRUE); //to enable
Exobiology answered 1/9, 2013 at 8:37 Comment(0)
R
2

Use with Vala + Gtk:

Gtk.Button play = new Gtk.Button.with_mnemonic("Play");
play.set_sensitive(false); // to gray-out
Rimma answered 24/4, 2018 at 4:5 Comment(0)
P
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

Psychologist answered 6/3, 2020 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.