Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt qml中的舞蹈设计_Qt_Animation_Qml - Fatal编程技术网

Qt qml中的舞蹈设计

Qt qml中的舞蹈设计,qt,animation,qml,Qt,Animation,Qml,是否可以在qml中使用动画(以可重用的方式)? 例如,在StackView中,从第1页过渡到第2页 我尝试了以下代码,但ParentChange无法按预期工作。此代码只是更改红色矩形的位置 import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 ApplicationWindow { visible: true width: 640 height: 480 title:

是否可以在qml中使用动画(以可重用的方式)? 例如,在StackView中,从第1页过渡到第2页

我尝试了以下代码,但ParentChange无法按预期工作。此代码只是更改红色矩形的位置

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

StackView {
    id: stack
    anchors.fill: parent

    initialItem: Page {
        id: page1
        Label {
            text: qsTr("First page")
            anchors.centerIn: parent
        }

        Rectangle {
            id: rect
            width: 50
            height: 50
            x: 600
            y: 100
            color: "red"

            states: [
                State {
                    when: stack.depth > 1
                    ParentChange { target: rect; parent: stack.currentItem; x: 100; y: 100; }
                }
            ]

            transitions: Transition {
                ParentAnimation {
                    NumberAnimation { properties: "x,y"; duration: 1000 }
                }
            }
        }

        MouseArea {
            anchors.fill: parent
            onClicked: stack.push(page2)
        }
    }

    Component {
        id: page2
        Page {
            background: Rectangle { color: "yellow"; anchors.fill: parent }
            Label {
                text: qsTr("Second page")
                anchors.centerIn: parent
            }
        }
    }
}

Rectangle {
    id: back
    color: "blue"
    width: 50
    height: 50
    radius: 25

    MouseArea {
        anchors.fill: parent
        onClicked: stack.pop()
    }
}
}

但其用途不限于
StackView
。它可以用于许多其他情况。(就像上面的链接一样)

请澄清您的问题。你试过了吗?你遇到问题了吗?请阅读之前的文章。@folibis-question-updatedThanks@Majid-Kamali更新问题。对我来说,如果你能解释一下你想要什么就好了。链接中的舞蹈动画看起来像是一个标准动画,完全类似于您开箱即用的QML动画。主要问题不是动画。这是关于重新租用物品的问题。当用户单击第1页时,“rect”不会保留在屏幕上,也不会转到第2页。您是否查看了StackView的所有转换属性?