このページでは

ParentChange QML Type

状態変化の際に、アイテムの親をどのように変更するかを指定します。詳細...

Import Statement: import QtQuick

プロパティ

詳細な説明

ParentChange は、画面上のアイテムの外観(位置、サイズ、回転、スケール)を維持したまま、その親要素を変更します。その後、トランジションを指定して、アイテムを移動・リサイズ・回転・拡大縮小し、最終的に意図した外観にすることができます。

ParentChangeは、複雑なトランスフォームが関与していない場合にのみ、視覚的な外観を維持できます。具体的には、親の変更に関与するアイテム(つまり、元の親と新しい親の共通の祖先ツリーにあるアイテム)のいずれかにtransformプロパティが設定されている場合、この機能は動作しません。

以下の例では、大きな赤い長方形と小さな青い長方形が並べて表示されています。「blueRect 」をクリックすると、「再親付け」された状態に変更されます。つまり、親が `redRect ` に変更され、ParentChange で指定された通り、赤い長方形内の (10, 10) の位置に配置されます。

import QtQuick

Item {
    width: 200; height: 100

    Rectangle {
        id: redRect
        width: 100; height: 100
        color: "red"
    }

    Rectangle {
        id: blueRect
        x: redRect.width
        width: 50; height: 50
        color: "blue"

        states: State {
            name: "reparented"
            ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }
        }

        MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" }
    }
}

親の再割り当てに影響を与える青い四角の状態変化

ParentAnimation を使用することで、トランジションのどの時点で ParentChange を実行するかを指定できます。

PropertyChanges とは異なり、ParentChangeはItemベースのターゲットを必要とする点に注意してください。任意のオブジェクトでは機能しません(たとえば、Timerの親を変更するために使用することはできません)。

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

height : real

rotation : real

scale : real

width : real

x : real

y : real

これらのプロパティは、この状態におけるアイテムの新しい位置、サイズ、スケール、および回転を保持します。

parent : Item

このプロパティには、この状態にあるアイテムの新しい親が格納されます。

target : 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.