Identify the default font

Hi, ALL,

If I build the Gtk-based app and I want t run it under KDE, where default GTK font may not be available, sice Qt/KDE have their own font system - what should app do?

Or even better - is it possible to somehow tell the app to use the default KDE font for the text control?

Thank you.

GTK relies on fontconfig on Linux and other Unix-like systems to match font names to font files; depending on the windowing system, either on GSettings (on Wayland) or the XSETTINGS notification mechanism on X11, to define the default font name for the UI text, though CSS can also be used to style widgets.

No. GTK has its own configuration system, and does not use KDE (for obvious reasons).

@ebassi ,

So basically all i need to do is to identify the font being used in GTK-based system, store it somewhere and then GTK internal mechanism will do the rest?

Thank you.

No.

On Wayland, you can get the font from GSettings:

❯ gsettings get org.gnome.desktop.interface font-name
'Inter Variable 10.5'

or set it:

gsettings set org.gnome.desktop.interface font-name 'Sans 10'

Under X11, you should have an XSETTINGS implementation running to bridge whatever configuration system.

You can also have a $HOME/.config/gtk-4.0/settings.ini with:

[Settings]
gtk-font-name=Sans 10

How “Sans” gets resolved to a specific font, it’s up to fontconfig’s configuration.

Hi @oneeyeman1

To add to what @ebassi said, you can rely on kde-gtk-config to translate KDE settings to XSettings/GSettings