En esta página

StyledItem QML Type

Muestra un DelegateStyle. Más...

Import Statement: import Qt.labs.StyleKit
Inherits:

Item

Status: Technology preview

Este tipo se encuentra en fase de vista previa tecnológica y está sujeto a cambios.

Propiedades

Descripción detallada

StyledItem representa un objeto ` DelegateStyle`. Lee propiedades como ` color`, ` border`, ` gradient` y ` image`, y crea internamente los elementos visuales correspondientes.

Si el delegate establecido en un DelegateStyle es null (el valor por defecto), se utilizará automáticamente StyledItem para la representación.

Se puede establecer un delegate personalizado para cualquier Item. Sin embargo, si se combina con un StyledItem, se puede conservar la representación predeterminada al tiempo que se añaden efectos de superposición, subyacente o de sombreado. El siguiente fragmento de código muestra cómo dibujar un Item adicional sobre el delegado predeterminado:

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"
            }
        }
    }
}

Nota: No se garantiza que los tipos de los módulos de Qt.labs sigan siendo compatibles en futuras versiones.

Para ver más ejemplos de superposiciones, fondos y efectos de sombreado, consulta el ejemplo «StyleKit Quick Controls».

Véase también DelegateStyle, delegate y data.

Documentación de propiedades

delegateStyle : DelegateStyle

El DelegateStyle que representa este elemento.

Esta propiedad es obligatoria. Cuando un elemento « StyledItem » es el elemento raíz de un « delegate », se establece automáticamente. Sin embargo, cuando se utiliza como elemento secundario dentro de un delegado personalizado, debe establecerse explícitamente.

El siguiente fragmento de código utiliza un delegado personalizado que dibuja una estrella debajo del control deslizante predeterminado. Dado que el elemento raíz no es un ` StyledItem`, declara una propiedad obligatoria ` delegateStyle ` (que se asigna automáticamente) y la reenvía al elemento secundario ` 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
        }
    }
}

Véase también « DelegateStyle », « delegate » y « 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.