このページでは

AnchorChanges QML Type

状態における項目のアンカーを変更する方法を指定します。詳細...

Import Statement: import QtQuick

プロパティ

詳細な説明

AnchorChanges 型は、State 内の項目のアンカーを変更するために使用されます。

AnchorChanges を使用してアイテムのマージンを変更することはできません。その場合は、代わりに `PropertyChanges ` を使用してください。

以下の例では、AnchorChanges を使用して項目の上部および下部のアンカーを変更し、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" }
}

2つの状態の間でアンカーの位置が変わる赤い四角形

AnchorChanges は、AnchorAnimation を使用してアニメーション化できます。

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

アンカーのマージンの変更は、NumberAnimation を使用してアニメーション化できます。

アンカーの詳細については、「アンカーレイアウト」を参照してください。

プロパティのドキュメント

anchors group

anchors.baseline : AnchorLine

anchors.bottom : AnchorLine

anchors.horizontalCenter : AnchorLine

anchors.left : AnchorLine

anchors.right : AnchorLine

anchors.top : AnchorLine

anchors.verticalCenter : AnchorLine

これらのプロパティは、アイテムのそれぞれのアンカーを変更します。

アンカーをリセットするには、undefined を割り当てます:

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

target : Item

このプロパティは、アンカーの変更が適用されるItem を保持します。

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