In GTK+3, how do I get a drawing_area to respond to mouse events?
In main() function I declared my drawing_area:
GtkWidget *drawing_area;
Then I connected the drawing_area with the mouse click signal:
g_signal_connect(drawing_area, "button-press-event", G_CALLBACK(clicked), NULL);
the function "clicked" is defined by:
static gboolean clicked(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
printf("Clicked! \n");
return TRUE;
}
The program runs and shows the drawing_area but when I click on it, no answer, nothing happens! Why is this happening?
It seems that GtkDrawingArea can not receive mouse events by default
Take a look to the documentation:
Or try connecting the event
"button-press-event"
to the window:instead of
As in this example:
http://zetcode.com/gfx/cairo/basicdrawing/