2010-09-18 153 views
1

我想要使用gtk_widget_modify_fg()更改GtkButton上显示的文本的颜色,但它不起作用。我已经使用gtk_widget_modify_bg()成功更改了GtkButton的背景,但前景一个不起作用。gtkbutton字体颜色变化

请帮忙。

问候 -DurgeshØ米什拉

回答

0

你可以把一个GtkLabel插件的按钮内部和颜色。请记住,用户喜欢与系统主题保持一致的程序。

1

您可以使用gtk_bin_get_child得到您的按钮GtkLabel的子控件,那么你应该能够改变其前景色与gtk_widget_modify_fg为您最初计划

示例(Python)可以在这里找到:How to set a Gtk2::Button's text colour

0

我也有这个麻烦。 我正在使用Mono Gtk#。 事实证明,每次更改按钮文本时,都会创建一个新的子标签小部件以显示文本。 每次更改文本时都必须更改子部件的前景色。

private void ChangeButtonTextAndColor (Button button, string text) 
    { 
     // Get forground color of the button widget to use for the label text color 
     var fore = button.Style.Foreground (StateType.Normal); 

     // Change the text - it will create a new label widget 
     // Note: Child will be NULL until some text is set 
     button.Label = text; 

     // Change the text color for the new label 
     // One color for all the different states 
     button.Child.ModifyFg (StateType.Insensitive, fore); 
     button.Child.ModifyFg (StateType.Active, fore); 
     button.Child.ModifyFg (StateType.Normal, fore); 
     button.Child.ModifyFg (StateType.Prelight, fore); 
     button.Child.ModifyFg (StateType.Selected, fore); 
    }