How to grey out a gtkmm menu item that cannot be clicked on

805 views Asked by At

I am using the library gtkmm in C++. This is the part of the code where I define "Open":

Gtk::ImageMenuItem *menuOpen = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::OPEN));
menuFile->append(*menuOpen);

I want "Open" to be greyed out if I cannot click on it, but I don't know the method which allows to do that. Any suggestions?

Thank you for your help.

1

There are 1 answers

0
AudioBubble On

In gtkmm 3 both Gtk::ImageMenuItem and Gtk::Stock have been deprecated, so it is best not to use them. Just use Gtk::MenuItem only with the text set to "_Open".

All widgets in gtkmm derive from Gtk::Widget. The method to use is Gtk::Widget::set_sensitive(bool).

To grey out or make insensitive your menu, use:

menuOpen->set_sensitive(false);

To re-enable the menu item:

menuOpen->set_sensitive();

If you want to find out if it is greyed out or not, use:

bool am_i_sensitive = menuOpen->get_sensitive();