I downloaded from Google Fonts two .ttf files on my project folder:
I set propperly the .qrc file in order to contain both of them.
Suppose I have the next .qml file:
import QtQuick 2.7
import QtQuick.Layouts 1.2
import QtQuick.Controls.Universal 2.0
Rectangle{
id: rectangle
height: 500
width: 700
Column{
FontLoader { id: myCustomFont1; source: "../Fonts/Montserrat/Montserrat-ExtraLight.ttf" }
FontLoader { id: myCustomFont2; source: "../Fonts/Montserrat/Montserrat-Black.ttf" }
Text{
...
text: "Qt for python"
font.family: myCustomFont1.name
...
}
Text{
...
text: "Qt for c++"
font.family: myCustomFont2.name
...
}
}
}
The problem is that the myCustomFont1.name
and the myCustomFont2.name
are the same, namely "Montserrat" and I don't have any solution to make distinction between them.
Therefore even if I specified the correct FontLoader-s id-s, the second text will have the same font.family like the first text.
Could be possible to solve this problem somehow?
This is not an ideal solution, but a workaround that should work. There's an open-source font editor called FontForge that you can use to change the names that Qt reads. Open the font files in question and then open the menu Element->Font Info
. That opens a dialog with multiple tabs on the left. The first tab should be PS Names
. This should list several fields including Fontname
and Family Name
. You should be able to edit those to whatever you want. Then close that dialog and use File->Generate Fonts
to regenerate the .ttf files.
Well, thx for this app. I installed it on my Mac and I changed those fields as per your instructions. But now the FontLoader name is absolutely blank. Doesn't have any name ...
Not sure why that would be. I haven’t had that problem when I’ve done it.
Great. Hope it works until you find a better solution.
After I played around with the new FontForge app I realized where should be made the modification: should navigate such as:
File->Element->Font Info
as you said and there shouldn't touch anything inPS Names
but rather should go inTTF Names
and in that particular table if exists the row Preferred Family, should modify the name as per desire. If not, should create a new row named like that and fill there the new desired Font Name. Thanks again. I will close the question considering good enough your answer.