I am trying to learn Qt and QML and I have hitten a wall. I want to be able to determine the screen factor of the display and choose a background image accordingly, but I cannot. This is my code:
import QtQuick 2.2
import QtQuick.Window 2.2
Image {
id: root
width: screenGeometry.width
height: screenGeometry.height
property real ratio: root.width / root.height
source: {
source = "../components/artwork/background.png"
if (ratio == 16.0 / 9.0) {
source = "../components/artwork/background_169.png"
}
else if (ratio == 16.0 / 10.0) {
source = "../components/artwork/background_1610.png"
}
else if (ratio == 4.0 / 3.0) {
source = "../components/artwork/background_43.png"
}
}
fillMode: Image.PreserveAspectFit
}
Independently from the screen size, it always choose the generic one. From what I could see trying to debug the problem, it seems that the value of variable ratio is not understood within the if statement. Searching for similar topics, I have found this one, but I can't still see the error.
Your help is much appreciated!