QML Opacity Inheritance

前端 未结 9 1988
刺人心
刺人心 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:48

    You can't. Items opacity value is relative to their parents one, so if you code something like

    Rectangle {
      color: "red"
      opacity: 0.5
      width: 200; height: 100
    
      Rectangle {
        color: "blue"
        opacity: 1
        width: 100; height: 100
      }
    }
    

    You will see that the two rectangles have the same opacity.

提交回复
热议问题