AnchorChanges QML Type
Indique comment modifier les ancrages d'un élément dans un état. En savoir plus…
| Import Statement: | import QtQuick |
Propriétés
- anchors
- anchors.baseline : AnchorLine
- anchors.bottom : AnchorLine
- anchors.horizontalCenter : AnchorLine
- anchors.left : AnchorLine
- anchors.right : AnchorLine
- anchors.top : AnchorLine
- anchors.verticalCenter : AnchorLine
- target : Item
Description détaillée
Le type AnchorChanges permet de modifier les ancrages d'un élément dans un State.
AnchorChanges ne peut pas être utilisé pour modifier les marges d'un élément. Pour cela, utilisez plutôt PropertyChanges.
Dans l'exemple suivant, nous modifions les ancrages supérieur et inférieur d'un élément à l'aide d'AnchorChanges, et les marges des ancrages supérieur et inférieur à l'aide d'PropertyChanges:
import QtQuick
Rectangle {
id: window
width: 120; height: 120
color: "black"
Rectangle { id: myRect; width: 50; height: 50; color: "red" }
states: State {
name: "reanchored"
AnchorChanges {
target: myRect
anchors.top: window.top
anchors.bottom: window.bottom
}
PropertyChanges {
target: myRect
anchors.topMargin: 10
anchors.bottomMargin: 10
}
}
MouseArea { anchors.fill: parent; onClicked: window.state = "reanchored" }
}
AnchorChanges peut être animé à l'aide de AnchorAnimation.
//animate our anchor changes
Transition {
AnchorAnimation {}
}Les modifications apportées aux marges d’ancrage peuvent être animées à l’aide de ` NumberAnimation`.
Pour plus d’informations sur les ancrages, consultez la section « Mises en page par ancrage ».
Documentation sur les propriétés
anchors group
anchors.baseline : AnchorLine
anchors.bottom : AnchorLine
anchors.horizontalCenter : AnchorLine
anchors.left : AnchorLine
anchors.right : AnchorLine
anchors.top : AnchorLine
anchors.verticalCenter : AnchorLine
Ces propriétés modifient les ancres respectives de l'élément.
Pour réinitialiser un ancrage, vous pouvez lui attribuer la valeur « undefined » :
AnchorChanges {
target: myItem
anchors.left: undefined //remove myItem's left anchor
anchors.right: otherItem.right
}target : Item
Cette propriété contient l’ Item e à laquelle les modifications d’ancrage seront appliquées.
© 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.