2010-09-18 117 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); 
    }