Tipi visivi
Il tipo Rectangle
Per gli elementi visivi più semplici, Qt Quick viene fornito il tipo ` Rectangle ` per disegnare rettangoli. Questi rettangoli possono essere colorati con un colore o con una sfumatura verticale. Il tipo ` Rectangle ` consente inoltre di disegnare bordi sul rettangolo.
Per disegnare forme personalizzate diverse dai rettangoli, consultare il tipo ` Canvas ` oppure visualizzare un'immagine pre-renderizzata utilizzando il tipo ` Image `.
import QtQuick
Item {
width: 320
height: 480
Rectangle {
color: "#272822"
width: 320
height: 480
}
// This element displays a rectangle with a gradient and a border
Rectangle {
x: 160
y: 20
width: 100
height: 100
radius: 8 // This gives rounded corners to the Rectangle
gradient: Gradient { // This sets a vertical gradient fill
GradientStop { position: 0.0; color: "aqua" }
GradientStop { position: 1.0; color: "teal" }
}
border { width: 3; color: "white" } // This sets a 3px wide black border to be drawn
}
// This rectangle is a plain color with no border
Rectangle {
x: 40
y: 20
width: 100
height: 100
color: "red"
}
}
Il tipo `Image`
Qt Quick fornisce un tipo ` Image ` che può essere utilizzato per visualizzare immagini. Il tipo ` Image ` dispone di una proprietà ` source `, il cui valore può essere un URL remoto o locale oppure l’URL di un file immagine incorporato in un file di risorse compilato.
// This element displays an image. Because the source is online, it may take some time to fetch
Image {
x: 40
y: 20
width: 61
height: 73
source: "http://codereview.qt-project.org/static/logo_qt.png"
}Per immagini più complesse esistono altri tipi simili a ` Image`. Il tipo ` BorderImage ` disegna un'immagine con ridimensionamento a griglia, adatto per immagini utilizzate come bordi. ` AnimatedImage ` riproduce immagini animate in formato .gif e .mng. ` AnimatedSprite ` e ` SpriteSequence ` riproducono animazioni composte da più fotogrammi memorizzati in modo adiacente in un formato immagine non animato.
Per la visualizzazione di file video e dati della fotocamera, consultare il Qt Multimedia modulo.
Proprietà visive condivise
Tutti gli elementi visivi forniti da Qt Quick si basano sul tipo "Elemento", che fornisce un insieme comune di attributi per gli elementi visivi, inclusi gli attributi di opacità e trasformazione.
Opacità e visibilità
I tipi di oggetti QML forniti da Qt Quick dispongono di supporto integrato per opacity. L’opacità può essere animata per consentire transizioni fluide da o verso uno stato trasparente. Anche la visibilità può essere gestita in modo più efficiente con la proprietà visible, ma a costo di non poterla animare.
import QtQuick
Item {
width: 320
height: 480
Rectangle {
color: "#272822"
width: 320
height: 480
}
Item {
x: 20
y: 270
width: 200
height: 200
MouseArea {
anchors.fill: parent
onClicked: topRect.visible = !topRect.visible
}
Rectangle {
x: 20
y: 20
width: 100
height: 100
color: "red"
}
Rectangle {
id: topRect
opacity: 0.5
x: 100
y: 100
width: 100
height: 100
color: "blue"
}
}
}
Trasformazioni
Qt Quick supportano nativamente le trasformazioni. Se si desidera ruotare o ridimensionare il contenuto visivo, è possibile impostare la proprietà Item::rotation o Item::scale. Anche queste possono essere animate.
import QtQuick
Item {
width: 320
height: 480
Rectangle {
color: "#272822"
width: 320
height: 480
}
Rectangle {
rotation: 45 // This rotates the Rectangle by 45 degrees
x: 20
y: 160
width: 100
height: 100
color: "blue"
}
Rectangle {
scale: 0.8 // This scales the Rectangle down to 80% size
x: 160
y: 160
width: 100
height: 100
color: "green"
}
}
Per trasformazioni più complesse, consultare la proprietà ` Item::transform `.
© 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.