Re: Interactive search on GtkTreeView not working




Hi Sofi,

I don't have OS X to test on but have been working on a few tree views recently. If I give it a quick test on Ubuntu, Ctrl+f and search works well in the following test code. Does this work on OS X or does it give you the same problem?

Eric


/*
    With Ubuntu16.04, GTK3.18 and GTK3.22.
    gcc -Wall tree_search1.c -o tree_search1 `pkg-config --cflags --libs gtk+-3.0`
*/
#include<gtk/gtk.h>

static GtkTreeStore* get_tree_store();

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), "Tree View");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkTreeStore *store=get_tree_store();

    GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
    gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), TRUE);
    g_object_unref(G_OBJECT(store));

    GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
    g_object_set(renderer1, "editable", TRUE, NULL);
  
    GtkTreeViewColumn *column1 = gtk_tree_view_column_new_with_attributes("Shape Coordinates", renderer1, "text", 0, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);

    GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
    gtk_widget_set_vexpand(scroll, TRUE);
    gtk_widget_set_hexpand(scroll, TRUE);
    gtk_container_add(GTK_CONTAINER(scroll), tree);  
   
    GtkWidget *grid=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
    gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
    gtk_container_add(GTK_CONTAINER(window), grid);
  
    gtk_widget_show_all(window);
    gtk_main();
    return 0;  
  }
static GtkTreeStore* get_tree_store()
  {
    gint i=0;
    gint j=0;
    GtkTreeStore *store=gtk_tree_store_new(1, G_TYPE_STRING);
       
    GtkTreeIter iter1;
    GtkTreeIter iter2;
    gtk_tree_store_append(store, &iter1, NULL);
    for(i=0;i<3;i++)
      {
        gchar *string1=g_strdup_printf("S%i", i);
        gtk_tree_store_set(store, &iter1, 0, string1, -1);
        g_free(string1);
        for(j=0;j<5;j++)
          {
            gtk_tree_store_append(store, &iter2, &iter1);  
            gchar *string2=g_strdup_printf("C%i", j);
            gtk_tree_store_set(store, &iter2, 0, string2, -1);
            g_free(string2);
          }
        gtk_tree_store_append(store, &iter1, NULL);
      }
 
    return store;
  }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]