Open
Conversation
Owner
|
thanks, i look at this. but at first sight i cannot see how user can understand what column was triggered? there can be more than one check/radio column and must be the easy way to inform callback about this |
Author
|
Thanks for taking a look. My use case completely missed that concept (I've got a single check box on a row so I didn't even think about that option). The column number is available so let me see what the best option would be to get that passed back. |
Contributor
|
You can create a custom GtkCellRenderer that displays a check button and use it as the header cell renderer for the column. // Define a custom cell renderer that displays a check button
GtkCellRenderer *check_renderer = gtk_cell_renderer_toggle_new();
g_object_set(check_renderer, "activatable", TRUE, NULL);
// Create a GtkTreeViewColumn and set the header cell renderer to the custom cell renderer
GtkTreeViewColumn *column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(column, "Check Column");
gtk_tree_view_column_set_widget(column, gtk_label_new("Check Column Header"));
gtk_tree_view_column_pack_start(column, check_renderer, TRUE);
gtk_tree_view_column_add_attribute(column, check_renderer, "active", COLUMN_NUMBER); // Replace COLUMN_NUMBER with the actual column number
// Connect the "toggled" signal of the custom cell renderer to a callback function that toggles the check buttons in the column
g_signal_connect(check_renderer, "toggled", G_CALLBACK(on_check_button_toggled), list_store);COLUMN_NUMBER variable should be set to the actual column number that contains the check buttons. The callback function could be something like this: void on_check_button_toggled(GtkCellRendererToggle *cell_renderer, gchar *path_str, gpointer user_data) {
GtkListStore *list_store = GTK_LIST_STORE(user_data);
gint column_number = COLUMN_NUMBER; // Replace COLUMN_NUMBER with the actual column number
GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
GtkTreeIter iter;
gtk_tree_model_get_iter(GTK_TREE_MODEL(list_store), &iter, path);
gtk_tree_path_free(path);
gboolean checked;
gtk_tree_model_get(GTK_TREE_MODEL(list_store), &iter, column_number, &checked, -1);
checked = !checked;
gtk_list_store_set(list_store, &iter, column_number, checked, -1);
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the toggle-action option to allow for a command to run when a checkbox or radio button is toggled in a list.
Uses the same code to call the command as select-action so I pulled that logic out and refactored it into a method that is called in all 3 spots.