GTK+ FAQ
<<< Previous | Development with GTK+: general questions | Next >>>

# How do I catch a double click event (in a list widget, for example)?

Tim Janik wrote to gtk-list (slightly modified):

Define a signal handler:

    gint
    signal_handler_event(GtkWidget *widget, GdkEventButton *event, gpointer func_data)
    {
      if (GTK_IS_LIST_ITEM(widget) &&
           (event->type==GDK_2BUTTON_PRESS ||
            event->type==GDK_3BUTTON_PRESS) ) {
        printf("I feel %s clicked on button %d\n",
               event->type==GDK_2BUTTON_PRESS ? "double" : "triple",
               event->button);
      }

      return FALSE;
    }

And connect the handler to your object:

    {
      /* list, list item init stuff */

      gtk_signal_connect(GTK_OBJECT(list_item),
                         "button_press_event",
                         GTK_SIGNAL_FUNC(signal_handler_event),
                         NULL);

      /* and/or */

      gtk_signal_connect(GTK_OBJECT(list_item),
                         "button_release_event",
                         GTK_SIGNAL_FUNC(signal_handler_event),
                         NULL);

      /* something else */
    }

and, Owen Taylor wrote:

"Note that a single button press will be received beforehand, and if you are doing this for a button, you will therefore also get a "clicked" signal for the button. (This is going to be true for any toolkit, since computers aren't good at reading one's mind.)"

<<< Previous | Home | Next >>>
How do I get the Window ID of a GtkWindow? | Up | By the way, what are the differences between signals and events?