Our QML application has a lot of text elements and all is looking good. But during the initialization we get a lot of point size errors for a number of Text elements.
QFont::setPointSizeF: Point size <= 0 (0.000000), must be greater than 0
The reason for this assert is that during the initialization phase the height of the element is empty (=0). I have created a small example to demonstrate this:
import QtQuick 2.2
Rectangle {
id: main
width: 640
height: 480
onHeightChanged: {
console.log("new height: ", height)
}
Text {
id: myText
height: parent.height
text: "Font Size Text"
font {
family: "Arial"
pointSize: 0.10 * myText.height
}
onFontChanged: {
console.log("new pointSize : ", myText.font.pointSize)
console.log(" myText height: ", myText.height)
console.log(" main height: ", main.height)
console.log(" parent height: ", parent.height)
}
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
anchors.centerIn: parent
}
}
The result is the following output:
qml: new pointSize : 8.25
qml: myText height: 0
qml: main height: 480
qrc:/qml/helloQml/FontSize.qml:26: TypeError: Cannot read property of null
qml: new pointSize : 48
qml: myText height: 0
qml: main height: 480
qml: parent height: 480
I have also used the QML Profiler to analyze the timeline and the pointSize is the first property that is binded and computed. So the resulting behavior is clear.
But what is the best way to prevent the assert message?
Thanks
↧