【发布时间】:2018-06-14 14:08:12
【问题描述】:
我有一个完全硬编码的 GtkTreeView,我正在尝试在 Treeview 中的一列上使用 Pango 标记。这需要在该列的文本渲染器上使用单元格数据函数。单元格数据函数的形式为:
// This function uses pango markup on the Gtklabels shown in the TreeView
// A cell data function is a function that is called for a specific cell renderer for each single row before that row is rendered.
static void cell_data_func_label (__attribute__((unused)) GtkTreeViewColumn *column, GtkCellRenderer *renderer,
GtkTreeModel *model, GtkTreeIter *iter, __attribute__((unused)) gpointer user_data)
{
gchar *label;
gchar *markuptxt;
// Retrieve the current label
gtk_tree_model_get (model, iter, CURRENT, &label, -1);
markuptxt = g_strdup_printf("<i>%s</i>", label);
g_object_set(renderer, "markup", markuptxt, "text", NULL, NULL); // markup isn't showing and text field is blank due to "text" == NULL
g_free(markuptxt);
}
在 GtkWidget *create_view_and_model() 函数中,我通过以下方式设置单元格数据函数:
// Sets the GtkTreeCellDataFunc to use for the column
gtk_tree_view_column_set_cell_data_func(column4, text, cell_data_func_label, NULL, NULL);
问题是文本单元格渲染器现在是空白的。我怀疑这可能与在 g_object_set 中的“文本”之后传递 NULL 有关。以下链接:
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderers
声明:
使用“标记”属性时,您需要考虑“标记”和“文本”属性似乎并不相互排斥(我想这可以称为错误)。换句话说:每当您设置“标记”(并且之前使用过“文本”属性)时,将“文本”属性设置为 NULL,反之亦然。
可能不再是这种情况(即它适用于 GTK+ 2),但我不确定需要更改哪些内容才能使用标记呈现列,因为除了 NULL 之外的任何内容最终都会被呈现没有标记,使用 NULL 会使渲染器为空。任何帮助将不胜感激。
【问题讨论】: