AnchorChanges QML Element

The AnchorChanges element allows you to change the anchors of an item in a state. 更多...

特性

詳細描述

The AnchorChanges element is used to modify the anchors of an item in a State .

AnchorChanges cannot be used to modify the margins on an item. For this, use PropertyChanges intead.

In the following example we change the top and bottom anchors of an item using AnchorChanges , and the top and bottom anchor margins using PropertyChanges :

import QtQuick 1.0
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 can be animated using AnchorAnimation .

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

Margin animations can be animated using NumberAnimation .

有關錨點的更多信息,見 錨點布局 .

特性文檔編製

錨點組

anchors.left : AnchorLine

anchors.right : AnchorLine

anchors.horizontalCenter : AnchorLine

anchors.top : AnchorLine

anchors.bottom : AnchorLine

anchors.verticalCenter : AnchorLine

anchors.baseline : AnchorLine

These properties change the respective anchors of the item.

To reset an anchor you can assign undefined :

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

target : Item

此特性保持 Item for which the anchor changes will be applied.