QML Opacity Inheritance

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

    I've bumped into this issue just now. Using Qt 5.1.0

    In my case, I had a Rectangle Element with opacity: 0.6 and a child Image element. The Image was inheriting the transparency - not desired.

    To solve it, I enclosed the main Rectangle in an Item element. Passed the size/position definitions from the Rectangle to the outer Item. Moved the Image outside the Rectangle.

    In the end, I had Item as the main parent and Rectangle and Image side by side, inside Item.

    Only Rectangle maintained the opacity 0.6, so the Rectangle has transparency and Image is fully opaque.

提交回复
热议问题