0

下面是gtktreeviewGTK+由 C 代码构建GtkListStore的。第一行是gtk_cell_renderer_text_new构建的标题。后面的行是内容。

假设有很多行,向下滚动时,如何找到标题正下方iter的行?例如,在初始时,header 正下方的行的 iter 为 0。向下滚动时,header 正下方的行的 iter 可能是 3 或 78 或其他。请注意,可能不会选择标题正下方的行。

我不知道:

首先,什么信号与“向下滚动”的动作有关?

其次,如何找到标题正下方的行?

请帮忙。谢谢你。

+----------+-----------+------------+----------------------+
|row ID    |title 2    |title 3     |title 4               |
|          |           |            |                      |
+----------+-----------+------------+----------------------+
|          |           |            |                      |
|    1     |           |            |                      |
+----------+-----------+------------+----------------------+
|          |           |            |                      |
|    2     |           |            |                      |
+----------+-----------+------------+----------------------+
|          |           |            |                      |
|    3     |           |            |                      |
+----------+-----------+------------+----------------------+
4

2 回答 2

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);
  .
  .
于 2013-10-17T09:51:36.390 回答
1

GtkTreeview 实现了 GtkScrollable,所以你可以做gtk_scrollable_get_vadjustment ()和连接到value-changed信号上的调整。

对于问题 #2,看一下gtk_tree_view_get_visible_range (): start_path 应该是第一个甚至稍微可见的行的路径。

于 2013-10-16T17:50:18.820 回答