0

I have Qt Resource file (res.qrc) in my Qt Application. I imported my custom font in resource as below:

:/fonts/aa_marcus_east_syriac.ttf

Also i define in header file:

private:
    QFont assyrianEventsAAMarcusEastSyriac;

I used QTextEdit in mainwindow. When user click on a button, my application read a text file. every row in text file should be imported in QTextEdit but some lines should be has aa_marcus_east_syriac.ttf font from my resource. So I wrote this codes:

void Widget::readMonthAssyrianEvents()
{
    QStringList eventsList;
    eventsList = readEventFile();

    ui->notificationTextEdit->setCurrentFont(assyrianEventsAAMarcusEastSyriac);

    for (int index = 0; index < eventsList.length(); index++)
    {
        QString eventType, eventContent;
        QStringList tempStringList = eventsList[index].split('|');

        eventType = tempStringList[0];
        eventContent = tempStringList[1];

        if (eventType == "0")
            ui->notificationTextEdit->append(eventContent);
    }
}

readEventFile() function works fine. It read text file and get all lines as QStringList. the "assyrianEventsAAMarcusEastSyriac" variable initialized in another function called init(). this is init() function:

int id = QFontDatabase::addApplicationFont(":/fonts/aa_marcus_east_syriac.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
assyrianEventsAAMarcusEastSyriac.setFamily(family);
assyrianEventsAAMarcusEastSyriac.setPointSize(20);

My problem is that QTextEdit doesn't change font of it's contents to my custom font.

How can I solve this problem? Please help me guys. Thanks

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Samson Davidoff
  • 101
  • 1
  • 9

1 Answers1

1

I think the error is in

QString family = QFontDatabase::applicationFontFamilies(id).at(0);

Have you checked that .at(0) is actually your custom font ?

Most likely you can solve this by calling assyrianEventsAAMarcusEastSyriac.setFamily with an explicit string of the font family just like

assyrianEventsAAMarcusEastSyriac.setFamily("Marcus East Syriac");

If that doesn't work either, maybe your custom font is malformed or doesn't provide a font family name. Therefore I suggest you to try first with a working font and then eventually go back to custom stuff.

Massimo Callegari
  • 2,099
  • 1
  • 26
  • 39