Question

So I am basically doing the following and I want SomeText to have red forground color. How to achieve this:

GtkWidget *menu_item =gtk_menu_item_new_with_labelex("SomeText");

I am using GDK 2.0

Thanks

Was it helpful?

Solution

Remember that GtkMenuItem is a GtkBin that contains a GtkAccelLabel. So all you have to do is stick a custom GtkAccelLabel into the GtkBin and make your label monitor the GtkMenuItem for accelerator keys.

So:

GtkWidget *menu_item, *accel_label;

accel_label = gtk_accel_label_new ("");
gtk_label_set_markup(GTK_LABEL (accel_label), "<span color=\"red\">This text will be RED!</span>");
menu_item = gtk_menu_item_new();
gtk_container_add(GTK_CONTAINER (menu_item), accel_label);
gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(accel_label), menu_item);
gtk_widget_show(accel_label);
gtk_widget_show(menu_item);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top