Since there is no mention in the answers/comments about QtDesigner, neither here nor in the linked posts, this is what I found about QtDesigner standalone (5.6) - about a font that is not installed in the system:
I've used a free font called AutobusBold.ttf
. First, path to this file needs to end up in your qrc file, mostly for the sake of Python - you can use Resource Browser/Edit Resources (the pencil) for this; you will end up with something like this in the .qrc file:
<file>myfont/AutobusBold.ttf</file>
If you open the .ttf file with fontview.exe
on Windows, you'll see its name is Autobus Bold
- with a space.
Then you need to close the .ui file in QtDesigner, then go to Settings/Additional Fonts... in QtDesigner (if an .ui file is open, then this option is greyed out); there click the + ("Add font file"), find the .ttf font file, and add it by selecting it and hitting Open. From now on, this font will appear whenever the Font dialog is opened in QtDesigner, mixed with the system fonts.
Then, reopen your .ui file, find the element you want to apply this font to and select it, in its styleSheet
option click the three dots, and from the resulting dialog window, click Add Font - you'll get the Font dialog, with all system fonts - but also the custom font will be there; select it, and you'll get a .qss stanza like this: font: 75 8pt "Autobus Bold";
That first 75 is probably font-weight
, you can also delete it, it will work the same; the 8pt is font-size
, and "Autobus Bold" is font-family
. Notice here that the font name in font-family
is quoted, as it has a space in the name - without the quotes, everything fails!
Then, if you write an extern .qss file, you can rewrite the font:
stanza as separate font-family
(with quoted font name!) and font-size
stanzas - and it should work the same.
Of course, if you want to transfer all this to Python, then you need to additionally addApplicationFont
as described in the answer by @GPPK.