Please nominate your Qt Champions for 2021! https://forum.qt.io/topic/132134/looking-for-the-2021-qt-champions

Regarding Z-order in QML



  • How would i increase the z-order of an image dynamically ? I tried by increasing z ,but didn't work . any other way of doing it so that i can manually control Z-order of two images when a state gets changed ?

    Thanks
    Krishkn



  • Are those two elements siblings? Could you post an excerpt of your qml code?



  • z works. in most of cases) so, the code



  • Z-order works for me, a simple sample

    @
    import Qt 4.7

    Item {
    width: 200
    height: 200

    Rectangle {
        id: red
        z: 1
        color: "red"
        width: 100; height: 100
    
        MouseArea {
            anchors.fill: parent
            onClicked: red.z = blue.z + 1
        }
    
    }
    
    Rectangle {
        id: blue
        color: "blue"
        x: 50; y: 50; width: 100; height: 100
    
        MouseArea {
            anchors.fill: parent
            onClicked: blue.z = red.z + 1
        }
    }
    

    }
    @



  • Old topic, but not answered...
    The z property of Item determines stacking order of sibling items, i.e. elements belonging to the same item.
    Hence you cannot use the z property to move a child of parent A on top of (a child of parent) B if B is on top of A. (Which is a pity/pain :-))

    https://doc.qt.io/qt-5/qml-qtquick-item.html#z-prop


Log in to reply