1
votes

When I use any method to select one of non-Default (or Base) styles in Qt Quick Controls 2 application (i.e. Universal or Material), then all the controls with text (like Label, TextField, whose font size must depend on QGuiApplication::font) uses font size value, which QCoreApplication has before changing:

QFont font = application.font();
bool ok = false;
font.setPointSize(QSettings{}.value("fontSize", 17).toInt(&ok));
Q_ASSERT(std::exchange(ok, false));
application.setFont(font);

Only Text, TextField are resized properly, but they are of no use in my GUI.

When I stick Default style, then all the mentioned items are resized properly.

How to make all the items be resized depending on global font.pointSize when used styles, other then Default?

Another connected question is how to get proper (means "contrast" and style-conformant) color for, say, highlighted text and background for the current style theme used? Using SystemPalette { id: palette } from ApplicationWindow in children gives colors suitable only for Default style (say palette.highlightedText is "white", palette.highlight is "blue" or "darkblue" (not sure)). It looks ugly in style themes, differs from Default.

Another important observation is: if I set font.pointSize: 17 (or equally font: Qt.application.font) in root ApplicationWindow, then all the items are resized properly, except of those of them which have new context: say, highlight: and delegate:s into *Views, sourceComponent:s into Loaders, default property item of Component and Repeater and others, where inheritance of the font breaks due to lost of the parent Item's context.

It seems, that I should to manually "inherit" ApplicationWindow.window.font for each new context. It is sad if so. It is boring, if e.g. in Repeater I use RowLayout with a plenty of Labels: in each of Label I have to add font: ApplicationWindow.window.font.

1
did you ever find a good solution for this? I have hit the same problem. - Colin
@Colin nope. Seems there is need in ticket/bug report. - Tomilov Anatoliy
thanks for the reply. The workaround I came up with works pretty well but was a bit of work: create a custom qt quick controls (2!) style and copy over the qml for each element (TextField, etc). Then use your method to modify those files at the top and set the control's font to the application font. - Colin

1 Answers

0
votes

Orient, I know it is too late, but one can also set font size in QApplication like this:

QFont font = QApplication::font();
font.setPointSizeF(fontSize);
QApplication::setFont(font);