c - 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.
解决方案
推荐阅读
- postgresql - Django ORM:如何通过 join 或 select_related() 从 ForeignKey("self") 获取评论子项?
- r - 通过在 R 中使用 group by 有条件地聚合,从因子变量中生成级别的列
- linux - 为什么 `test -w /tv` 给出不正确的否定结果?
- micronaut - 使用 micronaut 访问记录器记录用户
- amazon-web-services - 在widevine+dash DRM视频加密中,分段mp4上没有设置签名cookie
- python - 如果我添加颜色,则 plotly express 重新排序分类 x 轴散点图
- javascript - React native App 在 IOS 模拟器上不起作用
- python - 为什么 pandas 的 replace 方法不适用于 None 作为值?
- javascript - React native navigation.setParams 没有设置任何新参数
- address-sanitizer - 您可以在 ASAN sanitizer 之前运行用户定义的通行证吗?