gtkbutton font color change
I am trying to change the color of text displayed on GtkButton using 开发者_JAVA技巧gtk_widget_modify_fg() but it is not working. I have successfully changed the background of GtkButton using gtk_widget_modify_bg() but foreground one is not working.
Please help.
Regards -Durgesh O Mishra
you can get GtkLabel child widget of your button using gtk_bin_get_child, then you should be able to change its foreground color with gtk_widget_modify_fg as you initially planned
example (python) can be found here: How to set a Gtk2::Button's text colour
You could put a GtkLabel
widget inside the button and colour that. Keep in mind that users like programs that stay consistent with the system theme.
I was having this trouble too. I'm using Mono Gtk#. It turns out each time you change the button text it creates a new child Label widget to display the text. You have to change the foreground color for the child widget each time you change the text.
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);
}
精彩评论