how to set custom font to qlabel
Hi,
I add mylabels to form programmatically.
Now I set custom font to these labels as follow:
1.
Quote:
QFont font("MyFont001 ", 30, QFont::Bold);
myLabel->setFont(font);
or
2.
Quote:
myLabel->setStyleSheet(@"font: 9pt "MyFont001 ";");
Both can not change to myLabels' font to MyFont001
So I add a label at Qt Designer and change QLabel's font to my custom font. It's also same result.
How can I set custom font (ttf font) to qlabel programmatically?
Thanks.
Re: how to set custom font to qlabel
Have you checked the font object?
The first approach is the canonical way to do that but maybe your font object is not the font you are expecting, e.g. your font not being available to the system's font database.
Cheers,
_
Re: how to set custom font to qlabel
Thanks for your replay,
I checked my font name in font database and I found it.
Quote:
QString fontName;
QFontDatabase database;
foreach (const QString &family, database.families()) {
fontName= fontName + ";" + family;
}
Finally I found a error at font.
My custom font name has a space "MyFont001 " in name. It doe not work. So I'll compile my font again.
Thank anda_skoa.