This works, and fires whatever handler is connected to signal_clicked() but, it doesn't actually change the appearance of the button, or fire the "toggled" signal.
I'm not sure this is correct. The default clicked
handler for a ToggleButton
appears to result in the toggled
signal being fired, and the appearance changing as you'd expect.
But if you manually connect to the clicked
signal, and don't chain up to the default handler, then you stop this from happening! Took me a little while to work that out. I'm sure how exactly to go about doing the chain-up in gtkmm (I usually use C or Vala for GTK work), but it doesn't really matter as you can just let the default handler to its thing and connect to toggled
like you want to.
This is the test code I used:
#include <gtkmm.h>
void on_toggle()
{
g_print("Toggled\n");
}
int main(int argc, char **argv)
{
Gtk::Main kit(argc, argv);
Gtk::Window w;
Gtk::ToggleButton t("Click me");
Glib::RefPtr<Gtk::AccelGroup> group = Gtk::AccelGroup::create();
t.add_accelerator("clicked", group, GDK_KEY_N, (Gdk::ModifierType) 0,(Gtk::AccelFlags) 0);
t.signal_toggled().connect(sigc::ptr_fun(&on_toggle));
w.add_accel_group(group);
w.set_default_size(100, 100);
w.add(t);
w.show_all();
kit.run(w);
return 0;
}