I am trying to make entries "greyed-out" ie: disabled, rather than hidden


eg the Combobox model contains ('Scandvb','DVB module','DVDb5-Scan')
There is another comboox with a configuration file chosen

I want to be able to make one or more of the entries unselectable if
prerequites are not available or the wrong type of config file is selected,
but still show the option as a prompt

thanks

On 22 June 2017 at 21:09, <cecas...@aol.com> wrote:

>
>
> Hi Mike,
>
> What part of the combo box are you trying to disable? If you want to
> filter rows or columns you can set up a tree model filter to do so. Maybe
> something like the following?
>
> Eric
>
>
> /*
>     gcc -Wall combo_filter1.c -o combo_filter1 `pkg-config --cflags --libs
> gtk+-3.0`
>     Tested on GTK3.18 and Ubuntu16.04
> */
> #include<gtk/gtk.h>
> #include<stdlib.h>
>
> static gint combo_row=0;
>
> static void change_combo(GtkComboBox *combo2, gpointer *data)
>   {
>     combo_row=gtk_combo_box_get_active(combo2);
>     gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(data[1]));
>     gtk_combo_box_set_active(GTK_COMBO_BOX(data[0]), 0);
>   }
> static gboolean show_rgb(GtkTreeModel *model, GtkTreeIter *iter, gpointer
> data)
>   {
>     gchar *string=gtk_tree_model_get_string_from_iter(model, iter);
>     gint row=atoi(string);
>     g_free(string);
>
>     if(combo_row==1&&row<3)
>       {
>         g_print("Combo1 Don't Show %i\n", row);
>         return FALSE;
>       }
>     else
>       {
>         g_print("Combo1 Show %i\n", row);
>         return TRUE;
>       }
>   }
> int main(int argc, char *argv[])
>   {
>     gtk_init(&argc, &argv);
>
>     GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
>     gtk_window_set_title(GTK_WINDOW(window), "Combo Filter");
>     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>     gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
>     g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
>
>     GtkTreeIter iter;
>     GtkListStore *store=gtk_list_store_new(1, G_TYPE_STRING);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Yellow", -1);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Purple", -1);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Cyan", -1);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Red", -1);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Green", -1);
>     gtk_list_store_append(store, &iter);
>     gtk_list_store_set(store, &iter, 0, "Blue", -1);
>
>     GtkTreeModel *model=gtk_tree_model_filter_new(GTK_TREE_MODEL(store),
> NULL);
>     gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), (
> GtkTreeModelFilterVisibleFunc)show_rgb, NULL, NULL);
>
>     GtkCellRenderer *renderer=gtk_cell_renderer_text_new();
>
>     GtkWidget *combo1=gtk_combo_box_new_with_model(model);
>     gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), renderer, TRUE);
>     gtk_widget_set_hexpand(combo1, TRUE);
>     gtk_widget_set_vexpand(combo1, TRUE);
>     gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0);
>     gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1),
> GTK_CELL_RENDERER(renderer), "text", 0, NULL);
>
>     GtkWidget *combo2=gtk_combo_box_text_new();
>     gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 0, "1", "Show
> All");
>     gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo2), 1, "2", "Show
> RGB");
>     gtk_combo_box_set_active(GTK_COMBO_BOX(combo2), 0);
>     gtk_widget_set_hexpand(combo2, TRUE);
>     gtk_widget_set_vexpand(combo2, TRUE);
>     gpointer data[]={combo1, model};
>     g_signal_connect(combo2, "changed", G_CALLBACK(change_combo), data);
>
>     g_object_unref(G_OBJECT(store));
>
>     GtkWidget *grid=gtk_grid_new();
>     gtk_grid_attach(GTK_GRID(grid), combo1, 0, 0, 1, 1);
>     gtk_grid_attach(GTK_GRID(grid), combo2, 0, 1, 1, 1);
>     gtk_container_add(GTK_CONTAINER(window), grid);
>
>     gtk_widget_show_all(window);
>     gtk_main();
>     return 0;
>   }
>
>
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to