Search code examples
eventstreeviewgtktogglepropagation

Prevent GtkTreeRow from being selected when toggleButton is clicked


I use a Gtk Cell Renderer Toggle inside a treeView. When I click on the toggle button, the row where the toggle button is placed gets selected. I want to prevent this behaviour. I tried it by returning FALSE when the toggled signal is fired, so the event shouldn't be propageted through the parent widgets of the checkbox (the row, the treeView)...but it didn't work.

I want to keep selection feature enabled, so disabling this feature is not a solution

Here is how I did it:

renderer = gtk_cell_renderer_toggle_new();;
g_signal_connect (G_OBJECT(renderer), "toggled", (GCallback)(update_result_list_model), NULL);

And here is the callback, and it doesn't stop event propagation:

extern "C" gboolean update_result_list_model(GtkCellRendererToggle *cell,
    gchar *path_str,
    gpointer data)
{
    // Do some job....

    return false;

}

Thanks


Solution

  • Finally, I got it by using a boolean flag that I called "selectingCheckbox". Initially I set it to FALSE. On toggled signal callback I set it to TRUE. On row selection callback (not in toggled signal callback), I check the value of this flag. If the flag is FALSE, i let the row being selected by returning true. If the flag is true, I don't let the row being selected by returning false, and I set the flag to false