gpt4 book ai didi

c: GtkListStore row-changed event - 如何获取所选行的数据?

转载 作者:行者123 更新时间:2023-12-04 06:35:45 26 4
gpt4 key购买 nike

您好,我使用glade 编写了一个小型gtk 应用程序。
该应用程序包括一个列表存储。每当用户单击一行时,我都希望能够获取该行包含的信息。

在 row-changed 事件下使用 Glade 我添加了以下功能:

void gtk_tree_view_row_activated_event_handler(GtkWidget *widget, gpointer data) {

GtkTreeSelection *selection;
GList *rows_list;

selection = gtk_tree_view_get_selection(widget);
rows_list = gtk_tree_selection_get_selected_rows (selection, widget);
}

我如何从这里继续?

最佳答案

请检查以下代码是否适合您:

enum
{
LIST_ITEM = 0,
N_COLUMNS
};

void view_selected_foreach_func(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer userdata)
{
char *value;
gtk_tree_model_get(model, iter, LIST_ITEM, &value, -1);
g_print("%s is selected\n", value);
g_free(value);
}

void gtk_tree_view_row_activated_event_handler(GtkWidget *widget, gpointer data)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
gtk_tree_selection_selected_foreach(selection, view_selected_foreach_func, NULL);
}

我想另一种实现你想要做的事情的方法是为 GtkTreeSelection changed 定义一个处理程序。信号。下面是一个小例子:

设置树 View :
list = gtk_tree_view_new();
...
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
g_signal_connect(selection, "changed", G_CALLBACK(on_changed), label);

更改信号处理程序:
void on_changed(GtkWidget *widget, gpointer label)
{
GtkTreeIter iter;
GtkTreeModel *model;
char *value;

if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(widget), &model, &iter))
{
gtk_tree_model_get(model, &iter, LIST_ITEM, &value, -1);
g_print("%s is selected\n", value);
g_free(value);
}
}

希望这有帮助,问候

关于c: GtkListStore row-changed event - 如何获取所选行的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4906037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com