Change order of visible items

好久不见. 提交于 2020-01-16 05:51:07

问题


Is it possible to move up/down the visual items in order to change its overlapping? currently, the child hides its parent, but i'd like to have the reverse, i.e. the parent hides the child. Maybe some properties exists?


回答1:


Yes it's possible. You will need to change the z property of the involved items. According to the documentation:

Sets the stacking order of sibling items. By default the stacking order is 0.

Items with a higher stacking value are drawn on top of siblings with a lower stacking order. Items with the same stacking value are drawn bottom up in the order they appear. Items with a negative stacking value are drawn under their parent's content.

Hence, you only need to set z property of children to a negative value:

import QtQuick 2.4

Rectangle {
    width:800
    height: 480
    color: "yellow"
    // opacity: 0.5   (1)
    Rectangle{
        width: 100
        height: 100
        color:"red"
        z:-1
    }
}

In this example the inner Rectangle is not visible since its z property has a negative value. Uncomment the opacity assignament of the outer Rectangle in (1) to see it.



来源:https://stackoverflow.com/questions/31527916/change-order-of-visible-items

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!