Have you seen the gtkmm tutorial?
https://developer.gnome.org/gtkmm-tutorial/3.24/gtkmm-tutorial.html
One of the examples in the Menus and Toolbars chapter
has a menu with radio items.
There is also a menu demo among the gtkmm demo
programs.
https://gitlab.gnome.org/GNOME/gtkmm/-/blob/gtkmm-3-24/demos/gtk-demo/example_menus.cc
The demo program uses Gtk::RadioMenuItem.
If you want to simplify the future upgrade of
your program from gtkmm3 to gtkmm4, I recommend that you look at
the tutorial example in the first place. It does not use
Gtk::RadioMenuItem. There are no specialized radio button
classes or radio menu item classes in gtkmm4. (It's still
possible to make GUIs with radio buttons and radio menu items.)
I have another problem with the same popup menu: I
need certain menu
entries to be radio actions (that is, only one can be selected at
a time, but there are multiple such groups in the single popup menu).
For example, I have:
Gtk::RadioAction::Group group_to_move;
m_refToMoveWhite_action = Gtk::RadioAction::create(group_to_move, "ToMoveWhite", "White to play");
m_refToMoveBlack_action = Gtk::RadioAction::create(group_to_move, "ToMoveBlack", "Black to play");
where the menu is read from a .glade file with Gtk::Builder, containing:
<child>
<object class="GtkRadioMenuItem" id="ToMoveWhite">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">PlacepieceMenu.ToMoveWhite</property>
<property name="label" translatable="yes">White to play</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="ToMoveBlack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action_name">PlacepieceMenu.ToMoveBlack</property>
<property name="label" translatable="yes">Black to play</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
</object>
</child>
Now I want a function to be called when I click these entries.
In the 2.4 code I had something like:
m_refActionGroup->add_action(m_refToMoveWhite_action, sigc::mem_fun(*this, &ChessPositionWidget::on_menu_to_move_white));
m_refActionGroup->add_action(m_refToMoveBlack_action, sigc::mem_fun(*this, &ChessPositionWidget::on_menu_to_move_black));
But that doesn't compile anymore. Because so many things got deprecated, the types of many variables
had to change and now I can't combine them anymore :/.
Ie, m_refActionGroup now has the type:
Glib::RefPtr<Gio::SimpleActionGroup> m_refActionGroup;
maybe that has to be Glib::RefPtr<Gio::ActionGroup> before I can add both Gio::SimpleAction's
and Gtk::RadioAction to it? The latter isn't derived from Gio:Action either though :/.
I am totally stuck on this. Also cannot find any example that shows how to do this.
I am just very confused about how all this is supposed to work. Before it seemed like that
if I wanted to make a big pop-up menu then EVERY entry in the menu had to be an action
and well all of the same group (that was using Gtk::UIManager). Now I'm using Gio::Action
and Gtk::Builder instead and I have no idea how to make it working again.
Carlo Wood