I use gtkmm 3.24.5.
I would like to add a sigc callback to "destruction" of a widget. How can I connect? There is no such signal on Gtk::Widget. Can I do it using C API?
Thanks for your replies.
I have not found documentation specific to 3.24.5. However, in 3.24.4, Gtk::Widgets
inherits from sigc::trackable
which exposes a sigc::trackable::add_destroy_notify_callback
method. It seems to be what you are looking after. Here is a quick example to show how it works (Gtkmm 3.24.20):
#include <iostream>
#include <gtkmm.h>
void* DestructorCallback(void* p_in)
{
std::cout << "Button destruction!" << std::endl;
return nullptr;
}
class MainWindow : public Gtk::ApplicationWindow
{
public:
MainWindow();
private:
Gtk::Button m_button;
};
MainWindow::MainWindow()
: m_button{"Hello World!"}
{
m_button.add_destroy_notify_callback(nullptr, DestructorCallback);
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");
MainWindow window;
window.show_all();
return app->run(window);
}
The documentation does not say much (in fact, it says nothing) about what is supposed to be p_in
as well as the void*
return value from the callback though...
Hope this works in Gtkmm 3.24.5.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.