Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.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
C++ 为什么动画没有';你不在QML工作吗?_C++_Qt_Qml - Fatal编程技术网

C++ 为什么动画没有';你不在QML工作吗?

C++ 为什么动画没有';你不在QML工作吗?,c++,qt,qml,C++,Qt,Qml,我想在我的一个屏幕上设置我的全屏应用程序,所以我必须设置它的高度、宽度、x、y等等。但是我发现动画不起作用 我曾经认为这是因为我把它设置在一个目标屏幕上,所以我创建了一个测试代码,在这里我硬编码了x,y,但是动画仍然不工作,有人能告诉我为什么吗 我的测试代码如下: import QtQuick 2.6 import QtQuick.Window 2.2 Window { visible: true title: qsTr("Hello World") flags: Qt

我想在我的一个屏幕上设置我的全屏应用程序,所以我必须设置它的高度、宽度、x、y等等。但是我发现动画不起作用

我曾经认为这是因为我把它设置在一个目标屏幕上,所以我创建了一个测试代码,在这里我硬编码了x,y,但是动画仍然不工作,有人能告诉我为什么吗

我的测试代码如下:

import QtQuick 2.6
import QtQuick.Window 2.2

Window {
    visible: true
    title: qsTr("Hello World")
    flags: Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint
    opacity: 0.6
    id: root

    MouseArea {
        anchors.fill: parent
        onClicked: {
            //Qt.quit();
        }
    }

    Component.onCompleted: {
        root.x = 0;
        root.y = 0;
        root.width = Screen.width;
        root.height = Screen.height;
        initWindow.start();
    }

    PropertyAnimation {
        id: initWindow
        target: root
        from: 0
        to: Screen.height
        duration: 2000
        easing.type: Easing.InOutQuad
        onRunningChanged: {
            if(!initWindow.running && root.visibility != Window.Hidden){
                console.log("here is initWindow animation.")
            }
        }
    }


}

因为你不做任何动画。 您需要指定一个目标

只是一个粗略的猜测,但您可能想要设置高度的动画

Window {
    id: root
    visible: true
    title: qsTr("Hello World")
    //        opacity: 0.6 // Does not work for me
    // I want to have the frames and stuff for an example.

    MouseArea {
        anchors.fill: parent
        onClicked: {
            //Qt.quit();
        }
    }

    Component.onCompleted: {
        root.x = 0;
        root.y = 0;
        root.width = 1200;
        root.height = 800;
    }

    Behavior on height { // Starts the Animation with the set target, once the height is set to be changed
        NumberAnimation {
            id: initWindow
            duration: 200000
        }
    }
}
或者更接近您的代码:

Window {
    id: root
    visible: true
    title: qsTr("Hello World")

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }

    Component.onCompleted: {
        root.x = 0;
        root.y = 0;
        root.width = Screen.width;
        initWindow.start();
    }

    PropertyAnimation {
        id: initWindow
        target: root
        from: 0
        to: Screen.height
        property: 'height' // You need to declare which property should change.
        duration: 2000
        easing.type: Easing.InOutQuad
    }
}
请看评论,了解我所做的。
例如,我将代码中一些不必要的内容剥离出来。

您的代码很好,但忘记设置要设置动画的属性。