Get font family name from QFontDatabase::addApplicationFont

3k Views Asked by At

I'm using QFontDatabase:addApplicationFont, and it's working as intended, but I want to get the family font name from the last ttf file it loads up, since the intended use of it is letting the user use whatever font they point towards.

I mostly want to know if this is possible within QFont or if I'll have to rely on a different library for it.

QFontDatabase::addApplicationFont(font_path);
ui_vp_message->setFont(QFont(ttf_font_family_name, f_weight));
1

There are 1 best solutions below

3
On BEST ANSWER

You can get the names using the QFontDatabase::applicationFontFamilies() method:

int id = QFontDatabase::addApplicationFont(font_path);
if(id != -1){
    QStringList font_families = QFontDatabase::applicationFontFamilies(id);
    qDebug()<< font_families;
}