|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Handling events in custom widgetsI'm trying to create a custom widget, which needs to also handle
keyboard and mouse input. Basically I'm doing the same as the example in chapter 25.2 from the book, but I have 3 instances of my widget - e.g | Gtk::Paned* pane1 = new Gtk::HPaned; | Gtk::Paned* pane2 = new Gtk::VPaned; | Gtk::Widget* w1 = new MyWidget(); | Gtk::Widget* w2 = new MyWidget(); | Gtk::Widget* w3 = new MyWidget(); | add(m_VBox); | m_VBox.pack_start(*Gtk::manage(pane1), Gtk::PACK_EXPAND_WIDGET); | pane1->pack1(*Gtk::manage(w1), Gtk::EXPAND); | pane1->pack2(*Gtk::manage(pane2), Gtk::EXPAND); | pane2->pack1(*Gtk::manage(w2), Gtk::EXPAND); | pane2->pack2(*Gtk::manage(w3), Gtk::EXPAND); So what I try to do is handle keyboard and mouse input in the widget under the mouse cursor - just like other widgets (e.g Gtk::Entry) The problem is the event handlers in the MyWidget-Class (e.g on_key_press_event) are not triggered at all. If I set the CAN_FOCUS-flag of MyWidget, the w1 handles the keyboard input. I've tried other flags, but with no success. Setting event mask of the Gdk::Window appropriately(m_refGdkWindow->set_events(...)) didn't help also. What do I need to do in order to get my widget signaled when keyboard and mouse events occur? Thanks in advance _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
|
|
|
|
|
|
Re: Handling events in custom widgetsOn Mon, Jun 23, 2008 at 2:31 PM, Clive Hobson wrote:
> ... > Alternatively, you can derive from a widget that already creates a Gdk/X window and use add_events()/set_events(). The tutorial section you mentioned (http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-custom-widgets.html) has the code in on_realize() to create the window and set it for the widget. That's the first thing I did (inherited from DrawingArea). But then for some reasons I decided to inherit from Gtk::Widget and create the underlying window myself. I've created the window with the values from the tutorial example and m_refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes, GDK_WA_X | GDK_WA_Y); m_refGdkWindow->set_events(Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::KEY_PRESS_MASK | Gdk::ENTER_NOTIFY_MASK ); unset_flags(Gtk::NO_WINDOW); set_window(m_refGdkWindow); also tried calling Gtk::Widget::add_events(), setting window class and other things but with no success. So probably there is something missing... Anyway, when I'm inheriting from DrawingArea, everything works as expected - the event-handlers like e.g on_motion_notify() are triggered. I had to set the CAN_FOCUS flag and put a "grab_focus()" in on_enter_notify_event in order to handle keyboard input within the hovered widget, but I guess there is no easier way... I even got rid of my earlyer problem by disabling the double buffering of the widget (...). But it's still interesting to know: What do I need to do to convert something that inherits from DrawingArea to something only inheriting from Widget, preserving all functionality. Regards Teodosiy _______________________________________________ gtkmm-list mailing list gtkmm-list@... http://mail.gnome.org/mailman/listinfo/gtkmm-list |
|
|
|
| Free Forum Powered by Nabble | Forum Help |