cgtkmouse

How to detect mouse click over an image in GTK+?


I'm working on a project in C using gtk+ 2.0.

I must check if the user has pressed left click on a image. I thought to call a function when left click is pressed and to get the position of the mouse, but how can I do that?


Solution

  • The problem is that the GtkImage widget which is used to show an image in GTK+ does not generate events.

    It's a "nowindow" widget, meaning that it's a passive container, which is used to display information and not to interact with the user.

    You can fix that by wrapping the image in a GtkEventBox, which will add event support.