I added this font to resource: BYekan.ttf
I want to use this font in my application. I've tried this :
QFont font(":/images/font/BYekan.ttf"); nLabel->setFont(font); nLabel->setText(tr("This is for test")); layout->addWidget(nLabel);
But, I guess it's not working. How to use it?
Edit: After reading this question , I've tried again :
int fontID(-1); bool fontWarningShown(false); QFile res(":/images/font/Yekan.ttf"); if (res.open(QIODevice::ReadOnly) == false) { if (fontWarningShown == false) { QMessageBox::warning(0, "Application", (QString)"Impossible d'ouvrir la police " + QChar(0x00AB) + " DejaVu Serif " + QChar(0x00BB) + "."); fontWarningShown = true; } }else { fontID = QFontDatabase::addApplicationFontFromData(res.readAll()); if (fontID == -1 && fontWarningShown == false) { QMessageBox::warning(0, "Application", (QString)"Impossible d'ouvrir la police " + QChar(0x00AB) + " DejaVu Serif " + QChar(0x00BB) + "."); fontWarningShown = true; } else nLabel->setFont(QFont(":/images/font/Yekan.ttf", 10)); }
I compare this font and other font, but there isn't any different on Qt. why?
Qt normally uses fontconfig to provide access to system fonts. If fontconfig is not available, e.g. in dedicated embedded systems where space is at a premium, Qt will fall back to using QBasicFontDatabase . In this case, Qt applications will look for fonts in Qt's lib/fonts/ directory.
Qt uses 9px as default font size, but users (on Linux) can change this by using qtconfig .
int id = QFontDatabase::addApplicationFont(":/fonts/monospace.ttf"); QString family = QFontDatabase::applicationFontFamilies(id).at(0); QFont monospace(family);
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