ParentChange QML Type

指定在状态改变时如何重新代理一个项目。更多

Import Statement: import QtQuick

属性

详细说明

ParentChange 在保留项目在屏幕上的可视化外观(位置、大小、旋转和缩放)的同时,对其进行重新绑定。然后,您可以指定一个过渡,将项目移动/缩放/旋转/缩放至其最终预期外观。

只有在不涉及复杂变换的情况下,ParentChange 才能保持视觉外观。更具体地说,如果已为任何涉及再父级化的项目(即原始父级和新父级的共同祖先树中的项目)设置了变换属性,它将不起作用。

下面的示例显示了一个并排的红色大矩形和一个蓝色小矩形。单击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 需要一个基于项的目标;它不能用于任意对象(例如,你不能用它来重新代理一个定时器)。

属性文档

height : real

rotation : real

scale : real

width : real

x : real

y : real

这些属性用于保存此状态下项目的新位置、大小、比例和旋转。


parent : Item

此属性保存此状态下项目的新父级。


target : Item

此属性包含要重新父代的项目


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