[Qt-qml] Why child object overrides parent borders

michael.brasser at nokia.com michael.brasser at nokia.com
Thu Aug 19 01:03:08 CEST 2010


On 18/08/2010, at 1:48 PM, ext Zharkyn Kassenov wrote:
> I create parent and child rectangles. Parent rectangle have borders, clip property is true. Size of child rectangle is biggest than size of parent rectangle. And the borders of parent rectangle is not visible. Why child rectangle override borders of parent rectangle?

clip: true for a Rectangle will clip to the entire Rectangle, including the borders (see http://doc.qt.nokia.com/4.7-snapshot/qrect.html#rendering for a discussion of where Qt draws the borders). You can introduce a "clip item" to wrap the contents, like below, that will clip to the "inner rectangle". We could possibly change the default clip behavior for Rectangle to clip to the inner rect, but I'm not sure of all of the implications of this (it would, for example, also affect other things such hit testing).

> import Qt 4.7
> 
> Rectangle {
>    id: scene
>    width: 200
>    height: 200
> 
>    Rectangle {
>        id: rectangle1
>        x: 43
>        y: 37
>        width: 114
>        height: 75
>        color: "#cbf7cb"
>        border.width: 1
>        border.color: "#000000"
>        transformOrigin: "Center"
>        clip: true
         //clip: true
         Item {
             anchors.fill: parent
             anchors.margins: parent.border.width/2
             clip:  true
>        Rectangle {
>            id: rectangle2
>            width: 158
>            height: 56
>            color: "#c1c9f3"
>            anchors.top: parent.top
>            anchors.topMargin: 1
>            anchors.left: parent.left
>            anchors.leftMargin: 1
>        }
      }
>    }
> }

Regards,
Michael



More information about the Qt-qml mailing list