Stylesheet: linking custom fonts
-
Hi all
I have a specific font stored in a file (ttf). Now I want to link this font to my QLabel's font. I've done the following:
@label->setStyleSheet("font-family: url(C:/font.tff);");@
But this doesn't seem to work. Does anyone know how to link an external font to your Qt application's style sheet?
-
label->setFont() ?
-
Try QFontDatabase from Qt C++ or FontLoader from QML :)
Try:
@int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]
QStringList QFontDatabase::applicationFontFamilies ( int id ) [static]@@import QtQuick 1.0
Column {
FontLoader { id: fixedFont; name: "Courier" }
FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }Text { text: "Fixed-size font"; font.family: fixedFont.name } Text { text: "Fancy font"; font.family: webFont.name }
}@
-
cool, thanks
-
@Chuck:I have tried these two methods and it doesn't work on symbian
The first method always return -1
I am using Qt 4.7.3 -
Chuck, I think it's important to know whether QT C++ uses True Type Fonts already installed in the user's computer or if we can deploy our chosen TTF, to be used in a computer that doesn't have this TTF previously installed.
It seems a stupid doubt, but QT docs aren't clear enough - specially for beginners, like me. I don't know if I can use a specially designed personal TTF in my software (it would make my life easier, by using only Text Classes) or if I have to use bitmap images to get the exact text design I want in all plataforms.
As there are differences about TTF handling in Linux... and also because sometimes we need to use a special TTF in our programs, TTF deployment without the need to install a new font in the target computer would be a very useful feature to me.
I don't want to use QML - I am too old to learn a new language. In my old times, C++ was tough enough to be learned and in the present, I confess that QT libraries are being almost too much to be explored by a STL-er. :)
What can you and other experts say about?
(Please, forgive my awful english. It is not my mother language)
Valdemar Katayama Kjaer
Brazil[quote author="Chuck Gao" date="1306668207"]Try QFontDatabase from Qt C++ or FontLoader from QML :)
Try:
@int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]
QStringList QFontDatabase::applicationFontFamilies ( int id ) [static]@@import QtQuick 1.0
Column {
FontLoader { id: fixedFont; name: "Courier" }
FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }Text { text: "Fixed-size font"; font.family: fixedFont.name } Text { text: "Fancy font"; font.family: webFont.name }
}@[/quote]