2
votes

I have a completely hardcoded GtkTreeView and I am trying to use Pango Markup on one of the columns in the Treeview. This requires the use of a cell data function on the text renderer for that column. The cell data function has the form:

// 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);
}

and within the function GtkWidget *create_view_and_model() I set the cell data function via:

  // Sets the GtkTreeCellDataFunc to use for the column
  gtk_tree_view_column_set_cell_data_func(column4, text, cell_data_func_label, NULL, NULL);

The problem is that the text cell renderer is now blank. I suspect it might have to do with passing NULL after "text" in g_object_set. The following link:

https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderers

states that:

When using the "markup" property, you need to take into account that the "markup" and "text" properties do not seem to be mutually exclusive (I suppose this could be called a bug). In other words: whenever you set "markup" (and have used the "text" property before), set the "text" property to NULL, and vice versa.

It may be that this is no longer the case (i.e. it is for GTK+ 2), but I am not sure what needs to be changed in order to render the column with markup, since anything other than NULL ends up being rendered without markup, and using NULL leaves the renderer empty. Any assitance would be appreciated.

1

1 Answers

2
votes

What ended up working was simply not including any reference to "text" whatsoever in g_object_set:

g_object_set(renderer, "markup", markuptxt, NULL);