Font size for custom Object type based on standard font size
-
Hello everybody,
I'm working in an application which needs labels with font size bigger that standard Label element. Since I'm working with QtQuick.Controls 2, all font sizes are computed according to platform and screen resolutions, I don't have to worry about that and works fantastic (at least for platforms I need for the project).
My problem is about the approach to specify the font size for those bigger labels. I can't use a fixed value for font.pointSize or font.pixelSize because platform screen resolution issues. If I use font.pointSize with any fixed value, the "physical" size of the text varies on different devices/screen resolutions (Desktop, Tablet)
For example, I need a label for some kind of alerts, 50% bigger than a standard Label element. I'm using something like this:
// AlertLabel.qml Label { font.pointSize: font.pointSize * 1.5 font.bold: true color: "red" }
and works fine: the AlertLabel is displayed 50% bigger than a standard Label and is screen resolution cross-platform... but there is a warning (an expected one) I don't like:
QML Label: Binding loop detected for property "font.pointSize"
Apparently, this is something which QML supports anyway for this case and there are no other problems, but I don't know if this will be a issue in the future (performance?), and also don't like the warning :D ... or maybe the approach is good and I just have to ignore the warning.
I searched in documentation and forums about something I can use to avoid the loop (e.g. font.pointSize : Qt.ComputedFontSizeForThisPlatform * 1.5 ) or even with C++.
Any hint will be appreciated. Thanks!
Hugo
-
@hugOrtega Try:
Label { ... Component.onCompleted: { font.pointSize = font.pointSize * 1.5 } }