Question

As in title, is there a way to put variables into the string that is processed by gtk_label_set_markup() function?

More specifically, I call this function like this: gtk_label_set_markup(GTK_LABEL(labelRed), "<span font=\"14\" color=\"red\"><b>\t\tRed: 999"</b></span>");

But, instead of a static text that is '999', I want to put in this place an integer variable. Is it possible to do?

Greetings, WisNia

Was it helpful?

Solution

you can use g_strdup_printf() to build a string and pass it to gtk_label_set_markup():

char *str = g_strdup_printf ("<span font=\"14\" color=\"red\">"
                               "<b>\t\tRed: %d</b>"
                             "</span>",
                             value);

gtk_label_set_markup (GTK_LABEL (labelRed), str);

g_free (str); // remember to free the string allocated by g_strdup_printf()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top