Re: Eventbox doesn't work with a Gtk::Button?
- From: HeavyJoost <heavyjoost gmail com>
- To: gtkmm-list gnome org
- Subject: Re: Eventbox doesn't work with a Gtk::Button?
- Date: Thu, 20 Oct 2005 00:15:41 +0200
Thanks! :) signal_pressed() was what I needed, hehe, I feel stupid :P
Nickolai Dobrynin wrote:
The simplest would probably be to derive from Gtk::Button and overriding the on_pressed
call back. This way, you avoid doing things like
m_EventBox.set_events(Gdk::BUTTON_PRESS_MASK);
m_EventBox.signal_button_press_event().connect(sigc::mem_fun(*this, &ExampleWindow::on_eventbox_button_press) );
If, on the other hand, it is your intention to register an additional call back for the
"pressed" event, then you should do
m_Button.signal_pressed().connect .................
instead of the second line above, or otherwise you make the event box receive the "pressed" event rather than
the button itself. Thus, I also think that the first line (the one with set_event) should be removed.
Regards,
Nickolai
PS Unless HeavyJoost is your real name, I think, people on this list tend to use their actual names for posting.
On Wed, Oct 19, 2005 at 10:57:38PM +0200, HeavyJoost wrote:
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;
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]