ApplicationWindow font not changed by QGuiApplication::setFont
-
Better workaround right now is to set the font of the
QApplication
and set it also to theApplicationWindow.
This way you have all qml elements using the same font. ( Set the font as a contextProperty so if you change it in cpp you won't have to change it in yourApplicationWindow
) -
It works if you have a static UI but if you load dynamically some Widgets then they won't have the right font unless you set it each time you create a new one.
Are you sure? It looks like the font set by using QApplication::setFont() is working after QApplication::exec() has started running.
You should use #ifdef Q_OS_OSX .
Yeah, but "FOR_MACOSX" is just a macro in my program. Not all source files are using Qt.
For macOS version you can take a look at NSProcessInfo's operatingSystemVersion
Unfortunately, I think, that function is only available in 10.10 and later.
Better workaround right now is to set the font of the QApplication and set it also to the ApplicationWindow.
Oh, so in addition to calling QApplication::setFont(), you can call qmainwindow->setFont(), and that's enough? Thanks, I'll try that.
-
Are you sure? It looks like the font set by using QApplication::setFont() is working after QApplication::exec() has started running.
Well yes it still work for components that do respect the
setFont
such asText
. But components likeButton
, they will not be with the right font and therefore you will have to set it.Unfortunately, I think, that function is only available in 10.10 and later.
I forgot about QSysInfo. You should have everything you need in there.
Oh, so in addition to calling QApplication::setFont(), you can call qmainwindow->setFont(), and that's enough? Thanks, I'll try that.
Well in QML if I set the font to the
ApplicationWindow
then yes all elements that were not well handling thesetFont
are now using the right one.I found out what is the issue or at least pin pointed it.
If I useQQuick.Controls 1.x
,Button
does have the font set bysetFont
however if I switch toQQuickView.Controls 2.0
then it is not using the right font.My guess is that I have to define a style that uses the font I want instead of using
setFont
? -
I don't remember the case exactly, but just
setFont()
didn't work for me as well. So I ended up with this crutch (which works fine):int id = QFontDatabase::addApplicationFont(":/fonts/TitilliumWeb-Regular.ttf"); app.setFont(QFont(QFontDatabase::applicationFontFamilies(id).at(0)));
-
Just for the record, I don't use QQuick, so this is a broader problem.
-
Sounds there's indeed something fishy going on.
Can you create a minimal compilable example that shows the behaviour ?
-
@SGaist, will do, do you want me to send it to the bug report page ?
@veryqtperson , it is what I have done, my font is registered. -
@MaxL said in ApplicationWindow font not changed by QGuiApplication::setFont:
@SGaist, will do, do you want me to send it to the bug report page ?
@veryqtperson , it is what I have done, my font is registered.Yes, I don't think QFontDatabase has anything to do with it. I don't have a Sierra computer in front of me right now, but I think this simple program could be enought to demonstrate the problem:
int main(int argc, char **argv){ QApplication app(argc,argv); QString fontstring("Lato,10,-1,5,87,0,0,0,0,0"); // Change this string if you don't have this font on your computer. QApplication::setFont(fontstring); QMessageBox msgBox; msgBox.setText("This text is not printed using "+fontstring); msgBox.exec(); return 0; }
-
Sorry, the program I posted in the previous message didn't trigger the bug. I also tried to copy various things from the initialization of the program (the one that did trigger the bug) into 'main' above, but without any luck.
-
Hi guys,
You can find a small app that shows how the
setFont
is handle that you can download from my Google Drive