qtqmlantialiasing

qml components disappearing after enabeling layers


I have a Component for an sddm theme. At the moment I use the theme dark sugar as the base theme. The component looks like the following:

Item {
        id: hexagon
        property color color:"yellow"
        property int radius: 30

        //layer.enabled: true
        //layer.samples: 8

        Shape {
        //... Here some Positioning and other Stuff
                ShapePath {
                //... Here some Options and Pathlines
                }
        }
}

This works fine, but as soon as I uncomment both layer settings the component disappears. Does this happen, because I load the component like this:

Pane {
...
    Item {
    ...
       MyComponent {
            z: 1
        }
    }
}

Nor the Pane or the Item use layer but most Components in the Item use the z: 1 property.


Solution

  • As iam_peter says, the default width and height properties of any Item are 0, and layer.enabled sets the size of the offscreen texture to the item size. By default, the scene graph doesn't do any clipping: a child item can populate scene graph nodes outside its parent's bounds. But when you confine the children's rendering to a specific offscreen texture, anything that doesn't fit is clipped. Here's a more interactive example to play with this:

    import QtQuick
    import QtQuick.Controls
    
    Rectangle {
        width: 640
        height: 480
    
        Column {
            CheckBox {
                id: cbLE
                text: "layer enabled"
            }
    
            Row {
                spacing: 6
                TextField {
                    id: widthField
                    text: layerItem.width
                    onEditingFinished: layerItem.width = text
                }
    
                Label {
                    text: "x"
                    anchors.verticalCenter: parent.verticalCenter
                }
    
                TextField {
                    id: heightField
                    text: layerItem.height
                    onEditingFinished: layerItem.height = text
                }
            }
        }
    
        Rectangle {
            id: layerItem
            x: 100; y: 100
            border.color: "black"; border.width: 2
    
            layer.enabled: cbLE.checked
    
            Rectangle {
                width: 100
                height: 100
                color: "tomato"
                opacity: 0.5
            }
    
            Text {
                text: "this text will get clipped even when layer size is defined"
            }
        }
    }
    

    You can use renderdoc to see how the rendering is done; for example you can see the texture that is created by enabling the layer.