我正在编写一个使用 treeview 的 gtk3(C 语言)代码。
store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
cell = gtk_cell_renderer_text_new ();
col_pub=gtk_tree_view_column_new_with_attributes (
"Title", cell,
"text", COL_BIB_PUB,
NULL);
gtk_tree_view_column_set_sort_column_id( col_pub, ID_PUB);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), col_pub);
问题是我希望 TreeView 的每个单元格都是可编辑的,所以我需要这样的东西:
g_object_set(cell, "editable", TRUE, NULL);
但我不知道如何将编辑后的标志连接到文件/缓冲区。 如果有人好心指路,那将非常有帮助......可能是一个非常简短的例子。
最佳答案
只需将 Gtk.CellRendererText 连接到一个信号。所有使用此渲染器的 TreeViewColumn 都将连接到该信号。
g_signal_connect (G_OBJECT (cell), "edited", G_CALLBACK (cb), NULL)
void cb (GtkCellRendererText *rend, char*path, char*newtext, gpointer data)
{
// Do whatever you want with the newtext
........
// Since this signal emitted after cell being edited,
// you can use a global variable (a bool maybe) to indicate.
// gboolean switcher = 0
switcher = 1
}
如果这就是你想要的,因为你的问题不清楚
关于c - 编辑 gtkcellrenderertext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14490412/