change font of stackwidget
-
I have a GUI program debug for raspberry pi with one central widget and I use this code for change the font that add in resources file:
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); QFont nastaliq("Nastaliq",20,QFont::Normal); w.setFont(nastaliq); w.show(); return a.exec(); }
and it's work
and I have an other program with stack-widget and use above code it doesn't change font of GUI application why?
-
Hi,
Do you mean you set the font on the stack widget ? It's just a container widget forQStackedLayout so it doesn't have a "body" like QMainWindow.
-
If you want all your widgets to use the same font, then just set it through QApplication::setFont.
-
QFont doesn't take a path as parameter but the family name.
Use QFontDatabase to load your custom font, build the QFont object using the correct family name and then set it on QApplication.
-
Then show the current code you use.
-
@zhmh said in change font of stackwidget:
returns 0 to me
Which means the fond is loaded properly.
Use http://doc.qt.io/qt-5/qfontdatabase.html#applicationFontFamilies to get the font and set back to application.
Can you show the code ?
-
int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); qDebug() << fnt << QFontDatabase::applicationFontFamilies(fnt);
returns: 0 ("Nastaliq")
@Ratzz said in change font of stackwidget:
Can you show the code ?
this is my main.cpp:
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; int fnt=QFontDatabase::addApplicationFont(":/new/prefix1/Nastaliq.ttf"); qDebug() << fnt << QFontDatabase::applicationFontFamilies(fnt); QFont nastaliq("Nastaliq",20,QFont::Normal); w.setFont(nastaliq); w.show(); return a.exec(); }
-
@zhmh said in change font of stackwidget:
QFont nastaliq("Nastaliq",20,QFont::Normal);
You should set the font which you got from the http://doc.qt.io/qt-5/qfontdatabase.html#applicationFontFamilies
-
Where did you get that font from ?