En esta página

AnchorChanges QML Type

Especifica cómo modificar los puntos de anclaje de un elemento en un estado. Más información...

Import Statement: import QtQuick

Propiedades

Descripción detallada

El tipo AnchorChanges se utiliza para modificar los anclajes de un elemento en un State.

AnchorChanges no se puede utilizar para modificar los márgenes de un elemento. Para ello, utiliza en su lugar PropertyChanges.

En el siguiente ejemplo cambiamos los puntos de anclaje superior e inferior de un elemento utilizando AnchorChanges, y los márgenes de los puntos de anclaje superior e inferior utilizando 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" }
}

Cuadrado rojo que cambia la posición del ancla entre dos estados

AnchorChanges se puede animar utilizando AnchorAnimation.

//animate our anchor changes
Transition {
    AnchorAnimation {}
}

Los cambios en los márgenes de anclaje se pueden animar mediante ` NumberAnimation`.

Para obtener más información sobre los anclajes, consulta «Diseños de anclajes».

Documentación de propiedades

anchors group

anchors.baseline : AnchorLine

anchors.bottom : AnchorLine

anchors.horizontalCenter : AnchorLine

anchors.left : AnchorLine

anchors.right : AnchorLine

anchors.top : AnchorLine

anchors.verticalCenter : AnchorLine

Estas propiedades modifican los anclajes correspondientes del elemento.

Para restablecer un ancla, puedes asignarle un valor « undefined »:

AnchorChanges {
    target: myItem
    anchors.left: undefined          //remove myItem's left anchor
    anchors.right: otherItem.right
}

target : Item

Esta propiedad contiene el objeto ` Item ` al que se aplicarán los cambios en los anclajes.

© 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.