Nesta página

StyledItem QML Type

Exibe um DelegateStyle. Mais...

Import Statement: import Qt.labs.StyleKit
Inherits:

Item

Status: Technology preview

Este tipo está em pré-visualização tecnológica e está sujeito a alterações.

Propriedades

Descrição detalhada

O StyledItem renderiza um DelegateStyle. Ele lê propriedades como color, border, gradient e image e cria internamente os elementos visuais correspondentes.

Se o ` delegate ` definido em um ` DelegateStyle ` for ` null ` (o padrão), o `StyledItem` será usado automaticamente para a renderização.

Um delegate personalizado pode ser definido para qualquer Item. Mas, combinado com um StyledItem, é possível manter a renderização padrão enquanto adiciona efeitos de sobreposição, subcamada ou sombreamento. O trecho a seguir mostra como desenhar um Item adicional sobre o delegado padrão:

Style {
    component Star : Shape {
        id: star
        property color color
        ShapePath {
            fillColor: star.color
            scale: Qt.size(star.width, star.height)
            PathMove { x: 0.50; y: 0.00 }
            PathLine { x: 0.59; y: 0.35 }
            PathLine { x: 0.97; y: 0.35 }
            PathLine { x: 0.66; y: 0.57 }
            PathLine { x: 0.78; y: 0.91 }
            PathLine { x: 0.50; y: 0.70 }
            PathLine { x: 0.22; y: 0.91 }
            PathLine { x: 0.34; y: 0.57 }
            PathLine { x: 0.03; y: 0.35 }
            PathLine { x: 0.41; y: 0.35 }
            PathLine { x: 0.50; y: 0.00 }
        }
    }

    button {
        background.delegate: StyledItem {
            width: parent.width
            height: parent.height
            // Draw a star on top the default rendering
            Star {
                anchors.fill: parent
                color: "gold"
            }
        }
    }
}

Observação: não há garantia de que os tipos nos módulos do Qt.labs permanecerão compatíveis em versões futuras.

Para mais exemplos de sobreposições, subcamadas e efeitos de shader, consulte o Exemplo de Controles Rápidos do StyleKit.

Veja também DelegateStyle, delegate e data.

Documentação de propriedades

delegateStyle : DelegateStyle

O ` DelegateStyle ` que este item representa.

Essa propriedade é obrigatória. Quando StyledItem é o item raiz de um delegate, ela é definida automaticamente. Porém, quando usada como um item filho dentro de um delegado personalizado, ela deve ser definida explicitamente.

O trecho de código a seguir usa um delegado personalizado que desenha uma estrela abaixo da alça padrão do controle deslizante. Como o item raiz não é um ` StyledItem`, ele declara a propriedade obrigatória ` delegateStyle ` (que é atribuída automaticamente) e a repassa para o item filho ` StyledItem`:

Style {
    component Star : Shape {
        id: star
        property color color
        ShapePath {
            fillColor: star.color
            scale: Qt.size(star.width, star.height)
            PathMove { x: 0.50; y: 0.00 }
            PathLine { x: 0.59; y: 0.35 }
            PathLine { x: 0.97; y: 0.35 }
            PathLine { x: 0.66; y: 0.57 }
            PathLine { x: 0.78; y: 0.91 }
            PathLine { x: 0.50; y: 0.70 }
            PathLine { x: 0.22; y: 0.91 }
            PathLine { x: 0.34; y: 0.57 }
            PathLine { x: 0.03; y: 0.35 }
            PathLine { x: 0.41; y: 0.35 }
            PathLine { x: 0.50; y: 0.00 }
        }
    }

    slider.handle.delegate: Item {
        // Since the root item is not a StyledItem, the following
        // required properties must be defined explicitly:
        required property DelegateStyle delegateStyle
        required property QtObject control

        implicitWidth: delegateStyle.width
        implicitHeight: delegateStyle.height
        width: parent.width
        height: parent.height
        scale: delegateStyle.scale
        rotation: delegateStyle.rotation
        visible: delegateStyle.visible

        // Draw a star underneath the default handle delegate
        Star {
            width: parent.width * 2
            height: parent.height * 2
            anchors.centerIn: parent
            color: "gold"
        }

        StyledItem {
            // Forward delegateStyle into StyledItem. StyledItem doesn't
            // use 'control' for anything, so it can be omitted.
            delegateStyle: parent.delegateStyle
        }
    }
}

Veja também DelegateStyle, delegate e data.

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.