QML Opacity Inheritance

前端 未结 9 2015
刺人心
刺人心 2020-12-31 04:12

In QML, how can I prevent a child element from inheriting the opacity from its parent? I want to set different opacity values for the parent and it\'s child element.

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-31 04:46

    It's possible! You need to test in the Component.onCompleted scope the opacity of the parent. If its 0 you need to change the parent of your object to the parent of it's current parent.

    Example:

    Item{
        id:root
    
        Item{
            id:currentParent
            opacity: 0
            Item{
                id:item
                Component.onCompleted:{
                    if(parent.opacity === 0)
                        item.parent = currentParent.parent
                }
            }
        }
    }
    

提交回复
热议问题