How to detect double click on GtkColumnView in gtk4

How can I detect double click on GtkColumnView? I tried with the code below but it doesn’t work:

static void onDblClick(GtkGestureClick* self, gint n_press, gdouble x, gdouble y, gpointer user_data)
{
    if (n_press == 2) { // Detect double-click
        GtkColumnView *column_view = GTK_COLUMN_VIEW(user_data);
        GtkSingleSelection *selection = GTK_SINGLE_SELECTION(gtk_column_view_get_model(column_view));
        guint position = gtk_single_selection_get_selected(selection);
        
        if (position != GTK_INVALID_LIST_POSITION) {
            g_print("Double-clicked on row: %u\n", position);
        }
    }
}

GtkGesture* leftClick = gtk_gesture_click_new();
gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(leftClick), GDK_BUTTON_PRIMARY);
gtk_widget_add_controller (GTK_WIDGET(columnView), GTK_EVENT_CONTROLLER(leftClick));
g_signal_connect (leftClick, "pressed", G_CALLBACK (onDblClick), columnView);

This is a signal on the deprecated GtkTreeView, not a GtkColumnView.

You probably want to use the capture phase, instead of the default bubble phase.

So, how to catch double click on gtk4 column view?

Hi,

Have you tried to set Gtk.EventController.set_propagation_phase (GTK_PHASE_CAPTURE) on your GestureClick?

Sorry, I’m still using it

Have you set set_single_click_activate to true? Even if you do not connect to the activate signal, if you have then the click count n_press is not what you think it should be. It will be 1.

I suggest you add g_print("click count: %u\n", n_press); to the start of your function to see what is going on.

If you are not using set_single_click_activate, connect to the activate signal.

It’s ok. I wanted to avoid using activate for double click. I changed my code and activate is ok.