Detect click Gtk :: Image?

I tried to detect clic on Gtk::Image with gtkmm for more than 2 hours, but I could not get it to work. It compiles and cancels the penalty, but the event never fires.

Some things that I tried that compiled do not crash but do not work:

 m_image = manage(new Gtk::Image(Gtk::Stock::APPLY, Gtk::ICON_SIZE_BUTTON)); m_image->add_events(Gdk::ALL_EVENTS_MASK); m_hbox->pack_start(*m_image, Gtk::PACK_SHRINK); m_image->signal_button_release_event() .connect(sigc::hide(sigc::mem_fun(*this, &Todo::switchStatus))); m_image->show(); 

or

 #include <gtkmm/main.h> #include <gtkmm/window.h> #include <gtkmm/button.h> #include <gtkmm/stock.h> #include <gtkmm/image.h> #include <iostream> using namespace std; class Win : public Gtk::Window { public: Win(); bool link(GdkEventButton* e); private: Gtk::Image image; }; Win::Win() : image(Gtk::Stock::APPLY, Gtk::ICON_SIZE_BUTTON) { cerr << "created" << endl; image.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); image.signal_button_release_event().connect(sigc::mem_fun(*this, &Win::link)); image.show(); add(image); } bool Win::link(GdkEventButton* e) { cerr << "kuh" << endl; } int main(int argc, char *argv[]) { Gtk::Main app(argc, argv); Gtk::Window window; window.resize(300, 500); Win win; Gtk::Main::run(win); return 0; } 

Well, I don’t know what else I can do ... Any ideas? :)

Thanks in advance.

+4
source share
1 answer

From http://developer.gnome.org/gtkmm/unstable/classGtk_1_1Image.html :

Gtk :: Image - widget "without a window" (does not have its own Gdk :: Window), so it does not receive events by default. If you want to receive events on the image, such as button clicks, place the image inside Gtk :: EventBox, then connect to the event signals in the event window

So, I am trying to put a signal in an event box after wrapping an image using an EventBox.

+5
source

All Articles