gpt4 book ai didi

c - 单元格中的 GTK 组合框

转载 作者:行者123 更新时间:2023-11-30 14:49:15 26 4
gpt4 key购买 nike

我正在编写 GUI,在一个窗口中我有一个列表,每一行由 3 列组成。

第一列是 int - 这里很简单,我给出属性“text”并传递 int 值。我不确定它是否正确,但它有效。

第三列是图标 - 属性是“icon-name”,传递带有图标名称的字符串,效果很好。

第二列是一个组合框 - 属性是一个“模型”,传递的是 GTKtreeModel,但它不起作用我尝试了不同的变体但没有任何作用。

所以,想法是使用 gtk_cell_renderer_combo_new ();通过一个模型并将我的第二列作为组合框。然而现在我得到了这个:

GLib-GObject-WARNING **: unable to set property 'model' of type 'GtkTreeModel' from value of type 'gchararray'

我没有找到任何有关如何在树作品中制作组合框的 Material 或文档。有什么想法吗?

GtkWidget *type_list = gtk_tree_view_new();  //creating a main list

GtkCellRenderer *render;

render = gtk_cell_renderer_text_new (); // first column is text
GtkTreeViewColumn* row_n = gtk_tree_view_column_new_with_attributes("#",render,"text",0, NULL); // name and type
gtk_tree_view_append_column(GTK_TREE_VIEW(type_list), row_n); //insert attribute into list

render = gtk_cell_renderer_combo_new (); //second column is combo
GtkTreeViewColumn* type_colomn = gtk_tree_view_column_new_with_attributes("Type",render, "model" , 1, NULL); // name and type - model as GTK doc said it must be model
gtk_tree_view_append_column(GTK_TREE_VIEW(type_list), type_colomn); // insert attribute into list

render = gtk_cell_renderer_pixbuf_new(); // third column is icon
GtkTreeViewColumn* delete_raw = gtk_tree_view_column_new_with_attributes("Delete",render, "icon-name", 2, NULL); // name and type icon-name to pass image from stock
gtk_tree_view_append_column(GTK_TREE_VIEW(type_list), delete_raw); // insert attribute into list

GtkListStore *store = gtk_list_store_new(3,G_TYPE_INT,G_TYPE_STRING,G_TYPE_STRING); // describe list storage; 3 types, int, string, string, I'm not sure if it correct

//creating list of options
GtkTreeIter itr;
gtk_list_store_append(store,&itr);
int num = 1;


const gchar *type[] = {"1 option", "2 option", "3 option", "4 option", "5 option"};
GtkListStore *list = gtk_list_store_new(1,G_TYPE_STRING); //creating list store to pass in combo
for (int i=0;i++<4;){
gtk_list_store_insert_with_values(list,NULL,-1, 0,type[i-1],-1); // insert values into list
}
//____________________________
//g_object_set (G_OBJECT (render_combo), "model",list,"editable", TRUE,NULL); // unsuccessful try with g_object_set

gtk_list_store_set(store, &itr, 0, num, 1,GTK_TREE_MODEL(list), 2, "edit-delete", -1); //insert data to the row

gtk_tree_view_set_model(GTK_TREE_VIEW(type_list),GTK_TREE_MODEL(store));

g_object_unref (G_OBJECT (store)); // free memory
g_object_unref (G_OBJECT (list)); // free memory
gtk_container_add(GTK_CONTAINER(node_type),type_list);

最佳答案

您需要为组合框模型创建一个新商店。与 TreeView 完全不同。然后将此存储设置为组合框模型属性。然后将此行更改为:

GtkTreeViewColumn* type_colomn = gtk_tree_view_column_new_with_attributes("Type",render, "text" , 1, NULL); // name and type - model as GTK doc said it must be model

因为您没有将模型存储在模型中。您正在 TreeView 列中渲染 TreeView 模型的文本。

组合框是一个完全独立的对象,在编辑单元格时弹出(单击两次)。

我会发布一些 C 示例,但我最了解 Python,但从未在 C 中这样做过。

关于c - 单元格中的 GTK 组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49745124/

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