switchparent.qml:
import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Layouts 1.3
Window {
    id: window
    visible: true
    minimumWidth: 300
    minimumHeight: 300
    RowLayout {
        id: topLayout
        anchors.fill: parent
        anchors.margins: spacing
        Rectangle {
            id: leftRect
            Layout.fillWidth: true
            Layout.fillHeight: true
            objectName: "leftRect"
            color: "red"
            Rectangle {
                id: innerRect
                x: 10; y: 10
                width: (minimumWidth - 3*topLayout.spacing)/2 - 2*10
                height: width
                color: "blue"
                Text {
                    anchors.centerIn: parent
                    text: "%1\n%2, %3\n%4x%5".arg(innerRect.parent.objectName)
                                             .arg(parent.x).arg(parent.y)
                                             .arg(parent.width).arg(parent.height)
                    color: "white"
                }
            }
        }
        Rectangle {
            id: rightRect
            Layout.fillWidth: true
            Layout.fillHeight: true
            objectName: "rightRect"
            color: "green"
        }
    }
    contentItem.states: State {
        name: "switchToRight"
        ParentChange {
            target: innerRect
            parent: rightRect
            x: rightRect.width - innerRect.width - 10
            y: rightRect.height - innerRect.height - 10
        }
        PropertyChanges {
            target: innerRect
            color: "darkblue"
        }
    }
    contentItem.transitions: Transition {
        ParentAnimation {
            via: contentItem
            NumberAnimation {
                properties: "x, y"
                duration: 3000
            }
            ColorAnimation {
                duration: 3000
            }
        }
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            if (contentItem.state === "") {
                contentItem.state = "switchToRight";
            } else {
                contentItem.state = "";
            }
        }
    }
}2018年5月5日
switchparent.qml
登録:
コメント (Atom)
