import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow {
    visible: true
    width: 400
    height: 400

    Item {
        id: parentItem

        Rectangle {
            id: parentRect
            width: 200
            height: 200
            color: "red"
            opacity: parentItem.opacity

            onOpacityChanged: {
                console.log("opacity changed 1");
            }

            Rectangle {
                id: childRect
                x: 50
                y: 50
                width: 100
                height: 100
                color: "green"
                //THIS LINE BELOW SHOULD NOT BE NECESSARY IN ORDER TO PRINT "opacity changed 2" (but it is)
                //opacity: parentRect.opacity 

                onOpacityChanged: {
                    console.log("opacity changed 2");
                }
            }
        }
    }

    Button {
        text: "Change Opacity"
        onClicked: {
            parentItem.opacity = parentItem.opacity === 1.0 ? 0.5 : 1.0;
        }
    }
}

