Re: Editable toggle (checkbox) in a GtkTreeView?
- From: Mikoyan <miko2 pandora be>
- To: Pierre Sarrazin <sarrazip sympatico ca>
- Cc: gtk-list gnome org
- Subject: Re: Editable toggle (checkbox) in a GtkTreeView?
- Date: Sun, 21 Sep 2003 16:29:07 +0200
On Sun, 2003-09-21 at 10:07, Pierre Sarrazin wrote:
> Hi. I want a GtkTreeView with an editable text column and an
> editable "toggle" (checkbox) column. My current code has the former,
> but the latter does not work yet. Here is how the two columns are
> added to the view:
>
> renderer = gtk_cell_renderer_text_new();
> column = gtk_tree_view_column_new_with_attributes(
> _("Regular expression"),
> renderer,
> "text", COLUMN_REGEX,
> "editable", COLUMN_EDITABLE,
> NULL);
> gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
>
> renderer = gtk_cell_renderer_toggle_new();
> column = gtk_tree_view_column_new_with_attributes(
> _("Negate"),
> renderer,
> "active", COLUMN_NEGATE,
> "activatable", COLUMN_EDITABLE,
> NULL);
> gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
>
>
> The only row in the store is added with this:
>
> gtk_tree_store_append(store, &iter, NULL);
> gtk_tree_store_set(store, &iter,
> COLUMN_REGEX, "foo",
> COLUMN_NEGATE, FALSE,
> COLUMN_EDITABLE, TRUE,
> -1);
>
> The store was created with this:
>
> GtkTreeStore *store = gtk_tree_store_new(3,
> G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
>
>
> When I click on a the text field, I can edit it. When I click on the
> checkbox, it does not change.
>
> I've looked at the "Editable Cells" demo in gtk-demo (from the
> gtk2-2.2.2-0.ximian.5.3 RPM), but it does not use "toggle" columns.
>
> Has anyone successfully created an editable checkbox in a GtkTreeView?
Use the toggled signal on the renderer like this :
g_signal_connect (G_OBJECT(renderer), "toggled", G_CALLBACK
(your_callback), NULL);
"your_callback" would look like this :
static void your_callback(GtkCellRendererToggle *cell,
gchar *path_str,
gpointer data)
{
// get the treemodel from somewhere
GtkTreeIter iter;
GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
gboolean enabled;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, COLUMN_X, &enabled, -1);
enabled ^= 1;
// do something with the new enabled value, and set the new
// enabled value in your treemodel
gtk_tree_path_free (path);
}
I don't remember where I learned this, but I think it was from the
gtk-demo though.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]