如何获取 GtkCellRenderer 的 GtkTreeViewColumn?

发布于 2024-11-05 12:05:02 字数 1002 浏览 0 评论 0原文

一些 gtk 源代码侦查使我相信以下代码可以获取模型中存储属性的列。

但是,要从信号处理程序到达这一点,我需要获取 GtkCellRenderer 的父 GtkTreeViewColumn

除了传递树视图列之外,我不知道如何执行此操作直接(这消除了我首先包含需要更新的模型的能力)或传递 GtkTreeView 本身,这将使我能够访问模型,但不能访问 GtkTreeViewColumn代码>

相当复杂的问题。当然,如果有人知道内置 GTK 函数可以从 GtkCellRenderer 直接转到 GtkListStore 那就更好了。

void
treeview_combo_edited(GtkCellRendererCombo * widget, gchar * path, gchar * value, GtkListStore * model){
    GtkTreeIter iter;
    gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model),&iter,path);
    // How to get GtkCellRenderer's GtkTreeViewColumn to use in line below?
    GSList * attributes = g_object_get(treeviewcolumn,attributes);
    int colnumber = g_slist_nth_data(g_slist_position(g_slist_find(attributes,"text")) - 1);
    gtk_list_store_set
    (
        model,
        &iter,
        colnumber,
        value,
        -1
    );
}

编辑:可能可以直接传递树视图列来获取两个所需的变量,但我在获取单元格渲染器的属性时遇到了问题。我怎样才能得到它们呢?

Some gtk source code sleuthing has lead me to believe the following code can obtain the column in the model where an attribute is stored.

However, to get to this point from a signal handler I need to get a GtkCellRenderers parent GtkTreeViewColumn

I don't know how to do this, other than passing the treeview column directly (Which eliminates my ability to include the model that needs to be updated in the first place) or passing the GtkTreeView itself which would give me access to the model, but not the GtkTreeViewColumn

Quite a complicated problem. Of course if anyone knows a builtin GTK function to go from GtkCellRenderer straight to GtkListStore that would be much better.

void
treeview_combo_edited(GtkCellRendererCombo * widget, gchar * path, gchar * value, GtkListStore * model){
    GtkTreeIter iter;
    gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(model),&iter,path);
    // How to get GtkCellRenderer's GtkTreeViewColumn to use in line below?
    GSList * attributes = g_object_get(treeviewcolumn,attributes);
    int colnumber = g_slist_nth_data(g_slist_position(g_slist_find(attributes,"text")) - 1);
    gtk_list_store_set
    (
        model,
        &iter,
        colnumber,
        value,
        -1
    );
}

Edit: It might be possible to pass the treeviewcolumn directly to get both needed variables but I've run into problems getting the cell renderer's attributes. How do I get them at all?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

|煩躁 2024-11-12 12:05:02

是的,这个 API 似乎缺失了。在我的代码中我使用

GtkTreeViewColumn *column = gtk_tree_view_column_new();
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
g_object_set_qdata_full(G_OBJECT(renderer), g_quark_from_static_string("column"), (gpointer)column, NULL);

,然后您可以使用

GtkTreeViewColumn* column = (g_object_get_qdata(G_OBJECT(renderer), g_quark_from_static_string("column"));

从渲染器对象获取列。

Yes this API seems to be missing. In my code i use

GtkTreeViewColumn *column = gtk_tree_view_column_new();
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
g_object_set_qdata_full(G_OBJECT(renderer), g_quark_from_static_string("column"), (gpointer)column, NULL);

and then later you can use

GtkTreeViewColumn* column = (g_object_get_qdata(G_OBJECT(renderer), g_quark_from_static_string("column"));

To get the column from a renderer object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文