Best way to adjust the font size of multiple Gtk.TextViews

What is the best way to adjust the font size of multiple Gtk.TextViews simultaneously? The initial situation of the font can be chosen via CSS in a simple way, but after the TextViews are already created and in use, it is no longer so simple to do this for several of them (imagine the context of a note taker app, for example).

Options that I know of:

  1. Create a CSS class for this and add the class in all TextViews.

It’s simple, but it makes mandatory to establish several CSS classes with predefined font sizes, making impossible to generate the size dynamically.

  1. Use tags in Gtk.TextBuffer.

It allows dynamic variations but it doesn’t seem right to me when the idea is just to change the size of the displayed text, instead of actually changing the font size as a characteristic of the text (which, in this case, it isn’t)

Hi,

Yes, it’s the best way.

Not at all :slight_smile:

You can dynamically generate a small CSS snippet with the font size for that CSS class, and dynamically load it with Gtk.StyleContext.add_provider_for_display().

If you added previously such a CSS, you can unload it first with Gtk.StyleContext.remove_provider_for_display() to avoid infinite grow.

There are some example in this discussion: Wrap already attached Widget into a GtkFrame

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.