7

I have some fonts that I want to add to QGIS but not globally to my operating system. So "installing" them e. g. via right-click in Windows or copying them to /usr/share/fonts/ on Linux is no option for me.

How can I make just QGIS aware of additional fonts?

1 Answer 1

7

One approach would be using Qt's QFontDatabase object which QGIS uses and add fonts to it via Python:

from qgis.PyQt.QtGui import QFontDatabase
qfontdatabase = QFontDatabase()
qfontdatabase.addApplicationFont("/tmp/ChivoMono-SemiBold.ttf")
qfontdatabase.addApplicationFont("/tmp/ComicSans.otf")

The font will be available immediately after running the addApplicationFont method.

You can use this for example in a plugin or in a startup.py script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.