Problem with opacity for rectangle.



  • I have one parent rectangle with opacity of "0.5" i have added some more components in to it.
    problem is that the child components are also displayed with the opacity of "0.5".
    I tried to specify opacity for child components as 1 but still it is displaying opacity for child components.

    Code spinets:
    @
    Rectangle
    {
    id: mainRect
    anchors.fill: parent;
    visible: true;
    opacity: 0.5;
    color: "black"
    border.width: 0;

        Rectangle
        {
            id: childRect;
            anchors.bottom: parent.bottom;
            anchors.bottomMargin: 20;
            anchors.right: parent.right;
            anchors.rightMargin: 20;
            radius: 30;
            border.width: 5
            opacity: 1
            color: "white"
    

    @

    what might be the problem?

    Thanks.



  • Child element inherits parent's opacity and adds it's opacity. This is explained "here":http://doc.qt.nokia.com/4.7-snapshot/qml-item.html#opacity-prop . A workaround is

    @
    Rectangle
    {
    id: mainRect
    anchors.fill: parent;
    visible: true;
    opacity: 0.5;
    color: "black"
    border.width: 0
    }

    Rectangle
    {
    id: childRect;
    anchors.bottom: mainRect.bottom;
    anchors.bottomMargin: 20;
    anchors.right: mainRect.right;
    anchors.rightMargin: 20;
    radius: 30;
    border.width: 5
    opacity: 1
    color: "white"
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.