问题描述
是否可以向上/向下移动视觉项目以更改其重叠?目前,孩子隐藏了它的父母,但我想反过来,即父母隐藏孩子.也许存在某些属性?
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?
推荐答案
是的,这是可能的.您将需要更改相关项目的 z
属性.根据文档:
Yes it's possible. You will need to change the z
property of the involved items. According to the documentation:
设置同级项的堆叠顺序.默认堆叠顺序为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.
因此,您只需将子项的 z
属性设置为负值:
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
}
}
在这个例子中,内部 Rectangle
是 不可见的,因为它的 z
属性有一个负值.取消注释 (1) 中外部 Rectangle
的 opacity
赋值以查看它.
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.
这篇关于更改可见项的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!