Eventbox doesn't work with a Gtk::Button?



In the following code, when I change m_Label to a Gtk::Button, it doesn't receive events anymore, is this normal? If so, how can I do that for buttons?

#include <gtkmm/main.h>
#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
 ExampleWindow();
 virtual ~ExampleWindow();

protected:
 //Signal handlers:
 virtual bool on_eventbox_button_press(GdkEventButton* event);

 //Child widgets:
 Gtk::EventBox m_EventBox;
 Gtk::Label m_Label;
 Gtk::Tooltips m_Tooltips;
};

ExampleWindow::ExampleWindow()
: m_Label("Click here to quit, quit, quit, quit, quit")
{
 set_title ("EventBox");
 set_border_width(10);

 add(m_EventBox);

 m_EventBox.add(m_Label);

 //Clip the label short:
 m_Label.set_size_request(110, 20);

 //And bind an action to it:
 m_EventBox.set_events(Gdk::BUTTON_PRESS_MASK);
 m_EventBox.signal_button_press_event().connect(
   sigc::mem_fun(*this, &ExampleWindow::on_eventbox_button_press) );

 m_Tooltips.set_tip(m_EventBox, "Click me!");

 show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

bool ExampleWindow::on_eventbox_button_press(GdkEventButton*)
{
 hide();
 return true;
}

int main(int argc, char *argv[])
{
 Gtk::Main kit(argc, argv);

 ExampleWindow window;
 Gtk::Main::run(window); //Shows the window and returns when it is closed.

 return 0;
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]