GTK+ change font to spin button

2020-04-27 07:28发布

问题:

I created a spin button in GTK+ like this:

flow_spin = gtk_spin_button_new_with_range (100,1500,25);

and I want to change it's font and size. I googled in order to find a workaround because it seems that the spin button widget doesn't change it's format natively, but nothing worked.

This:

flow_spin.Child.ModifyFont(FontDescription.FromString("Courier 16"));

as well as this, didn't work:

flow_spin.Markup = "<span size='38000'>big text</span>";

As for this, the plus and minus buttons got bigger, but the text area remained the same size:

gtk_widget_set_size_request ( flow_spin,50, 50);

I look if possibly for a method, similar to this ?

gtk_label_set_markup (GTK_LABEL (label), "<span font='8' foreground='black' weight='normal'>100</span>");

Since I am a beginner at C as well as GTK+, any suggestions would be appreciated.

回答1:

Gtk supports CSS for styling. You can load a CSS file in your program with gtk_css_provider_load_from_file().

So, just add a style provider on GtkWidget you want to stylish.

It's good read:

  • http://developer.gnome.org/gtk3/stable/theming.html
  • https://thegnomejournal.wordpress.com/2011/03/15/styling-gtk-with-css/


标签: c gtk