Using gtkmm 3.0 with c++, in a Gtk::Window, I have a Gtk::Label named "bezeichnung" showing text.
How can I change the font of this label?
There seems to be no function to set the font for a Gtk::Label. To deal with functions of the general Gtk::Widget from which Gtk::Label derives is difficult to understand, since it uses Pango. This is my code so far:
Pango::FontDescription font;
font.set_family("Monospace");
font.set_weight(Pango::WEIGHT_ULTRABOLD);
font.set_size(14 * PANGO_SCALE);
bezeichnung = Gtk::Label("leer");
bezeichnung.set_halign(Gtk::ALIGN_CENTER);
auto context = bezeichnung.create_pango_context();
context->set_font_description(font);
The font does not change. How can I set the changed Pango context back to the label?
Here is a solution, close to yours, that works for me on Ubuntu with Gtkmm 3.24.20:
I am no Pango expert, but I think the problem was the use of:
Its description from the docs:
So this is a copy of the widget's context, not its context. Why
set_font_descriptiondid not set that copy as the new context is not explained in the docs... In my opinion this looks like an API design flaw. It should at least be mentioned.