Re: Overriding on_motion_notify_event
- From: José Alburquerque <jaalburquerque cox net>
- To: Thomas Clark <thechewanater gmail com>
- Cc: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: Overriding on_motion_notify_event
- Date: Mon, 16 Aug 2010 22:37:29 -0400
On Aug 16, 2010, at 7:36 PM, Thomas Clark <thechewanater gmail com> wrote:
> I'm trying to override the virtual function on_motion_notify_event in a
> Gtk::DrawingArea, but the function never seems to be called. I don't get why,
> since DrawingArea inherits from Widget. So, when does a motion notify event ever occur?
>
> Here's a minimal example of what I mean:
>
> #include <iostream>
> #include <gtkmm.h>
>
> class Area: public Gtk::DrawingArea
> {
> public:
> Area () {}
> private:
> //never called?
> virtual bool on_motion_notify_event (GdkEventMotion *event)
> {
> std::cout << event->x << '\t' << event->y << '\n';
> }
> };
>
> int main (int argc, char **argv)
> {
> Gtk::Main test (argc, argv);
> Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
> Area area;
>
> window.add (area);
> window.show_all ();
>
> test.run (window);
> }
The C API "motion-notify-event" docs[1] suggests that the Gdk::POINTER_MOTION_MASK of the Gdk::Window needs to be set to get those events. This can be done by using Gtk::Widget::add_events() or Gtk::Widget::set_events(), or by getting the Gdk::Window and setting the mask using Gdk::Window::set_events().
[1] http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-motion-notify-event
--
José
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]