改变GTK 上的菜单的文字属性

来源:互联网 发布:android编程兵书 pdf 编辑:程序博客网 时间:2024/04/29 04:44

change the word's attribute from the menu of GTK 
改变GTK 上的菜单的文字属性

 


gtk_menu_item_new_with_label ()
GtkWidget*          gtk_menu_item_new_with_label        (const gchar *label);
Creates a new GtkMenuItem whose child is a GtkLabel.
label :
the text for the label
Returns 
:

 

the newly created GtkMenuItem always has a label ,and we can get it's child 's attribute.

新生成的menuitem里面都有一个Label,直接取得其child设置即可

 Build the  menu and Show it .

生成菜单并且显示它。


   GtkMenuShell *menu;
   GtkWidget *menuitem;


   menuitem=gtk_menu_item_new_with_label("hello");
   gtk_container_foreach (GTK_CONTAINER(menuitem), menu_set_text, NULL);
   gtk_menu_shell_append(menu,menuitem);


   gtk_widget_set_size_request (menuitem, 120, 35);
   gtk_widget_show(menuitem);


   gtk_menu_popup(GTK_MENU(menu), NULL, NULL, popmenu_set_position, NULL, ev->button, ev->time);




the function to change the word 's attribuates.
改变菜单上的文字属性的函数。

 void menu_set_text(GtkWidget * w)
{
    g_return_if_fail(w != NULL);


    char *bold_text=NULL;
    GtkLabel* label = GTK_LABEL(w);


    g_return_if_fail(label != NULL);


    bold_text = g_markup_printf_escaped ("<span weight=/"bold/">%s</span>", gtk_label_get_text (GTK_LABEL (w)));
    gtk_label_set_markup (label, bold_text);
 }

原创粉丝点击