Search code examples
c++qtqt5qfont

Get font family name from QFontDatabase::addApplicationFont


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));

Solution

  • 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;
    }