I’m working in GTK3+ in C on Debian and trying to specify a monospace font for both
I see how to do this using Glade (for Gtk_Label only), but have been searching for how to do it programatically in C and have not been successful in finding code samples. I tried just using some reference docs, but I’m missing something since I can’t even get the code to compile.
I also tried creating an .ini file but did not know the format, so that failed (& would have been generic across all fonts in the program, which I would like to avoid if possible).
Can anyone point me in the right direction for this please? Thanks!
Do you think such a statement will attract many helpful people? What about reading a good book – at least C books exists, GTK books not that many unfortunately.
I think for modern GTK you have to use CSS, which is unfortunately not just a single statement in code. I do most in code too, but maybe it is easier with an XML UI file. For code, I once created this example, it is for GTK4, but I think it is not that different from latest GTK3:
As you do not intend to do it dynamically with a font chooser, you can ignore a lot of the code. But I think you need the CssProvider and the loadFromData() function. I think when you accept that there is not a single function call available, but you need the CSS stuff, then you will manage to do it in C and GTK3. If not, let us know, I may be able to provide a full example in the next days… But maybe you would prefer to use an XML UI file? Let us know.
I just remembered an old GTK3 example, it uses CSS for color, but you should be able to tune it:
For the books: For GTK3 there is not much, I am aware of a Python GTK3 book, based on the GTK2 book of A. Krause. I have seen a few pages, would not recommend. But GTK4 is out for more than a year now. There is a free C book, see https://github.com/ToshioCP/Gtk4-tutorial. There is my GTK4 Nim one, at least a start: GTK4 for Graphical User Interfaces. And there are the Michi B youtube videos. For more see