0
votes

I have built a GTK GUI using Glade, which mean I have a *.glade file that I can use with my application. I have been able to get widgets to interact with them, but I am clueless as to how I can connect a signal handler to a Menu entry.

The signal I want to connect is the one that is emitted when you click on the menu entry. Like you would do in you web browser, you go to File, then click on one entry.

What is the name of that event, and what is the gtkmm function to call ? I am confused as to what element I should be trying to interact with, is it the GtkMenu, GtkMenuShell... ? Even better, can I do it from Glade's interface ?

At first I thought the event was activate-current so I tried to use the method which would logically connect to it, like you would do for a clicked event on a button.

Here's the code that is not working, because the method doesn't exist:

Gtk::MenuShell* help_menu; p_builder->get_widget("helpMenu", help_menu); help_menu->signal_activate_current().connect(sigc::ptr_fun(&on_help_menu_activate_current));

src/GUI.cpp:11:16: error: ‘class Gtk::MenuShell’ has no member named ‘signal_activate_current’ help_menu->signal_activate_current().connect(sigc::ptr_fun(&on_help_menu_activate_current));

1

1 Answers

0
votes

GtkMenuShell is an abstract class, you are probably looking for GtkMenu or GtkMenuBar. Both implement GtkMenuShell.

The items on the menus are GtkMenuItem and you'll probably want the "activate" signal from these items.

The MenuItem widget and the derived widgets are the only valid children for menus.

Their function is to correctly handle highlighting, alignment, events and submenus.

You can set the callback name via Glade and then connect the handlers programmatically via GtkBuilder methods.