Re: Handling events in custom widgets



On 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


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