PDA

View Full Version : QApplication::setFont issues



ChildishJack
23rd June 2017, 10:57
In my main.cpp I set the font of the application like so:


//Font
QString fontPath = ":/data/COUR.TTF";
int id = QFontDatabase::addApplicationFont(fontPath);
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont default_font(family);

QApplication::setFont(default_font);
This works, mostly. For whatever reason all of the application that I can see correctly applies this font except for my most parent widget, QTabWidget.

I also have this snippet of code that is activated on a button press, inside a MainWindow function:


QApplication::setFont(QFontDialog::getFont(0, QApplication::font()));
When activated during runtime, this error is produced:


2017-06-13 21:10:14.622 MYAPP[36930:4140590] Layout still needs update after calling -[QNSPanelContentsWrapper layout].
QNSPanelContentsWrapper or one of its superclasses may have overridden -layout without calling super.
Or, something may have dirtied layout in the middle of updating it. Both are programming errors in Cocoa Autolayout.
The former is pretty likely to arise if some pre-Cocoa Autolayout class had a method called layout, but it should be fixed.
(Edited a little for visual clarity)

I've looked at this bug report, which shows the exact same error and a similar-ish code, it may be relevant: https://bugreports.qt.io/browse/QTBUG-58699

Their code:


QColorDialog::getColor(QColor(1., 1., 1.), myWindow, "My Title", QColorDialog::DontUseNativeDialog);
That error is not produced by the MainWindow function if I remove the main.cpp settings, which makes me doubt its actually this bug. In addition, the MainWindow function correctly applies the font chosen to all but a few (seemingly) random widgets.

They (From the bug report) are on OSX 10.11.6, I am as well. They reported it for QT 5.8, I'm experiencing it with QT 5.9 and 5.8. If this is the case, this doesn't surprise me, as the bug report does not indicate it has been fixed. I can reproduce it on the QT Creator built debug version, and a statically built release version.

So my question boils down to these points:

1) Why does the main.cpp font code not work across all widgets?

2) Why does that MainWindow function not override the main.cpp settings?

3) Why does that MainWindow function (With the main.cpp part removed) not apply the settings to the entire application?

4) Are there better/easier ways to accomplish what I'm trying to do? (Set a font on application start, and provide a way for the user to customize it later)