0

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

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236

1 Answers1

0

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
  • 3,490
  • 1
  • 15
  • 8
  • What if I already have an existing item and would like to change the color at runtime. Is it possible? –  Jul 16 '09 at 22:24
  • 1
    Yes, it's possible. gtk_label_set_markup( GTK_LABEL(gtk_bin_get_child(GTK_BIN (menu_item))), "Some text" ); – tetromino Jul 16 '09 at 23:12