tags:

views:

70

answers:

1

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

A: 

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);
tetromino
What if I already have an existing item and would like to change the color at runtime. Is it possible?
Yes, it's possible. gtk_label_set_markup( GTK_LABEL(gtk_bin_get_child(GTK_BIN (menu_item))), "<span color=\"red\">Some text</span>" );
tetromino