I would like to retrieve the font file path with its extension (for example "arial.ttf").
The QFont::rawname() method always returns "unknown".
Is there another way to obtain the name and the extension of a font?
Here is the code we use:
bool ok = true;
QFont font = QFontDialog::getFont(&ok, this);
if(ok)
{
QString fontpath = "/Library/Fonts/" + font.family()+".ttf";//Using font file path in the application
}
A QFont is a request for a font, not a description of an actual font that matched; the latter is QFontInfo
. See my other answer. Unfortunately, QFontInfo
does not give you rawName()
. There is a roundabout way to get it if at all, you're not guaranteed that it will work on all platforms.
QFont myFont;
QFontInfo info(myFont);
QFont realFont(info.family());
QString rawName = realFont.rawName();
If you're looking for standard locations of things such as fonts, then in Qt 5 you'd use QStandardPaths::standardLocations
with FontsLocation
. In Qt 4, you'd use QDesktopServices::storageLocation
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With