I don't understand the behavior of opacity in the following code!
import QtQuick 2.4
Rectangle {
id: root
width: 640; height: 480
Rectangle {
id: wrapper
width: 600; height:440
anchors.centerIn: parent
color: "black"
opacity: 0.5
Rectangle {
id: belowcover
width: cover.width / 2
height: cover.height / 2
anchors.centerIn: parent
color: "green"
z: 1
}
Rectangle {
id: cover
width: root.width / 2
height: root.height / 2
anchors.centerIn: parent
color: "red"
z: 1
}
Rectangle {
id: seen
width: 100; height: 100
radius: width
color: "blue"
z: -1
}
}
}
The wrapper
has opacity of 0.5 so that I could see through it in order to see the circle seen
. But both cover
and belowcover
have opacity of 1, and as belowcover
is smaller than cover
, it should not be seen (or rather I expect it not to be seen, or am I missing something?). But both cover
and belowcover
are seen. I want only the circle to be seen through wrapper
, and belowcover
is to remain hidden below cover
. How can I do this? I have observed that setting the z
of cover
higher than that of belowcover
does not make the latter hidden.
Edit:
I have observed that when opacity of parent is set to less than 1, the children objects become less opaque, even though their opacity
remains at 1, as seen when printed to console. I don't understand why.