In questa pagina

StyledItem QML Type

Visualizza un’immagine DelegateStyle. Altro...

Import Statement: import Qt.labs.StyleKit
Inherits:

Item

Status: Technology preview

Questo tipo è in anteprima tecnologica ed è soggetto a modifiche.

Proprietà

Descrizione dettagliata

StyledItem genera un oggetto di tipo DelegateStyle. Legge proprietà quali color, border, gradient e image e crea internamente gli elementi visivi corrispondenti.

Se l’ delegate impostato su un DelegateStyle è null (il valore predefinito), per il rendering verrà automaticamente utilizzato StyledItem.

È possibile impostare un delegate personalizzato su qualsiasi Item. Tuttavia, in combinazione con uno StyledItem, è possibile mantenere il rendering predefinito aggiungendo effetti di sovrapposizione, sottofondo o shader. Il seguente frammento di codice mostra come disegnare un Item aggiuntivo sopra il delegato predefinito:

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: non è garantita la compatibilità dei tipi nei moduli Qt.labs nelle versioni future.

Per ulteriori esempi di effetti di sovrapposizione, sottofondo e shader, consultare l’esempio StyleKit Quick Controls.

Vedi anche DelegateStyle, delegate e data.

Documentazione sulle proprietà

delegateStyle : DelegateStyle

L'DelegateStyle che questo elemento genera.

Questa proprietà è obbligatoria. Quando ` StyledItem ` è l'elemento radice di un ` delegate`, viene impostata automaticamente. Tuttavia, se utilizzata come elemento figlio all'interno di un delegato personalizzato, deve essere impostata esplicitamente.

Il frammento di codice seguente utilizza un delegato personalizzato che disegna una stella sotto il cursore predefinito. Poiché l’elemento radice non è un ` StyledItem`, dichiara una proprietà obbligatoria ` delegateStyle ` (che viene assegnata automaticamente) e la inoltra all’elemento figlio ` 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
        }
    }
}

Vedi anche 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.