首页 > 解决方案 > GTK TreeViewColumn Titles Disappear

问题描述

I have a program that parses text files into distinct words and displays them plus their counts via GTK 3 in a tree view. One column is "Word" and the other is "Count".

For some reason, when a file has more than 1638 distinct "Words", the tree view no longer shows the column names, even though the parsing and word display proceeds normally. See the screenshots.

The words are stored in a struct:

 typedef struct Word{

     char * _origWord;
     char * _word;
     int _number;
     struct Word * _left;
     struct Word * _right;
     Line * _line;

} Word;

"Line" is another struct for noting the lines the words appear on.

Here is the code where each "Word" is added to the GtkTreeStore:

 static void store_words_counts(Word *w, GtkTreeStore *store, GtkTreeIter iter){

     if (w->_word == NULL) return;

     store_words_counts(w->_left, store, iter);

     if (strlen(w->_origWord) > 0 && strAlpha(w->_origWord)){

         gtk_tree_store_append (store, &iter, NULL);

         int length = snprintf( NULL, 0, "%d", w->_number);
         char * number = malloc(length + 1);
         snprintf(number, length + 1, "%d", w->_number);


         gtk_tree_store_set(store, &iter,
                            0, w->_origWord,
                            1, number,
                           -1);


         free(number);
     }

     store_words_counts(w->_right, store, iter);

 }

And here is the code where the columns are created:

 GtkTreeStore * store = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_STRING);

 /*  Load the data - call to parser */

 load_tree_store(store, contents);

 GtkWidget * tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));

 GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);

g_object_unref (G_OBJECT (store));

GtkCellRendere *renderer = gtk_cell_renderer_text_new();

GtkTreeViewColumn *column = gtk_tree_view_column_new ();

gtk_tree_view_column_set_title (column, "Word");
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_set_attributes(column, renderer, "text", 0, NULL);

printf("title is: %s\n", gtk_tree_view_column_get_title(column));

//column = gtk_tree_view_column_new_with_attributes ("Word", renderer,
//                                                   "text", 0,
//                                                   NULL);  

I am not using an enum for column numbers so that I could make sure the columns were being created correctly. I also commented out a quicker way of creating the columns and did it step by step. When I check the titles of the columns after creating and loading them, the titles print correctly to stdout.

Any idea why they are not rendering past a certain number of data being loaded? Thanks.

Fewer than 1638 distinct words

enter image description here

标签: cgtk

解决方案


推荐阅读