以下是gtktreeview
由GtkListStore
在 GTK + 中由C代码构建的iter
。第一行是由 gtk_cell_renderer_text_new 构建的标头。接下来的行是内容。
假设有很多行,向下滚动时,如何在标题下面找到行的+----------+-----------+------------+----------------------+
|row ID |title 2 |title 3 |title 4 |
| | | | |
+----------+-----------+------------+----------------------+
| | | | |
| 1 | | | |
+----------+-----------+------------+----------------------+
| | | | |
| 2 | | | |
+----------+-----------+------------+----------------------+
| | | | |
| 3 | | | |
+----------+-----------+------------+----------------------+
?例如,在初始时,标题下方的行的iter为0.向下滚动时,标题下方的行的iter可以是3或78或其他。请注意,标题下方的行可能会选择不。
我不知道:
首先,什么信号与动作相关联"向下滚动"?
其次,如何找到标题下方的行?
请帮忙。谢谢。
{{1}}
答案 0 :(得分:1)
GtkTreeview实施GtkScrollable,因此您可以执行gtk_scrollable_get_vadjustment ()
并在调整时连接到value-changed
信号。
对于问题#2,请查看gtk_tree_view_get_visible_range ()
:start_path应该是第一个稍微可见的行的路径。
答案 1 :(得分:1)
根据jku的回答,该问题的解决方案是:
void treeview_vadjustment_changed (GtkWidget *widget, gpointer data)
{
GtkTreePath *start_path;
if(gtk_tree_view_get_visible_range(treeview, &start_path, NULL))
{
gchar *str;
GtkTreeIter start_iter, iter;
GtkTreeModel *model = gtk_tree_view_get_model(treeview);
if(gtk_tree_model_get_iter(model, &start_iter, start_path) && ACC_truss_get_truss_weight_iter (model, start_iter, &iter))
{
int who;
GtkWidget *window = g_object_get_data(G_OBJECT(treeview), "parent_window");
gtk_tree_model_get(model, &iter, TRUSS_MEM_AXIS_NAME, &str, -1);
who = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(model), "which_truss"));
switch(who)
{
case 0:
gtk_entry_set_text((GtkEntry *)g_object_get_data(G_OBJECT(window), "ACC_SDD_main_truss_curr"), str);
break;
case 1:
gtk_entry_set_text((GtkEntry *)g_object_get_data(G_OBJECT(window), "ACC_SDD_second_truss_curr"), str);
break;
}
g_free(str);
}
}
gtk_tree_path_free(start_path);
}
.
.
store = gtk_list_store_new(TRUSS_NUMS_MEM_SEC, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
switch(who)
{
case 0:
g_object_set_data(G_OBJECT(window), "ACC_main_truss_SDD_mem_tree_store", store);
break;
case 1:
g_object_set_data(G_OBJECT(window), "ACC_second_truss_SDD_mem_tree_store", store);
break;
}
model = GTK_TREE_MODEL(store);
/* create tree view */
treeview = gtk_tree_view_new_with_model(model);
g_object_set_data(G_OBJECT(treeview), "parent_window", window);
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
/* gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COLUMN_DESCRIPTION);*/
ACC_member_treeview_header_truss (GTK_TREE_VIEW(treeview), who);
g_object_unref(model);
gtk_widget_show(treeview);
gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
vadjustment = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(treeview));
g_signal_connect(vadjustment, "value-changed", G_CALLBACK(treeview_vadjustment_changed), treeview);
.
.