2017-01-06 2 views
0

Ich möchte meine Vollbild-App auf einem meiner Bildschirme einstellen, also muss ich Höhe, Breite, x, y und so weiter einstellen. Ich fand jedoch, dass die Animation nicht funktioniert.Warum funktioniert meine Animation in QML nicht?

Ich dachte immer dies verursacht durch Ich setzte es auf einem Zielbildschirm, also erstelle ich einen Test-Code, hier hart Code X, y, aber die Animation funktioniert immer noch nicht, kann mir jemand sagen, warum?

Mein Testcode ist wie folgt:

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.") 
      } 
     } 
    } 


} 
+0

Ihr Code ist gut, aber Sie vergessen, eine Eigenschaft zu setzen, die Sie animieren möchten. – folibis

Antwort

1

Weil Sie nichts animieren. Sie müssen ein Ziel angeben.

Nur eine wilde Vermutung, aber Sie möchten wahrscheinlich die Höhe animieren?

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 
     } 
    } 
} 

Oder, um Ihren Code näher zu bleiben:

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 
    } 
} 

die Kommentare sehen, für das, was ich tat. Und ich streifte Ihren Code von einigen Sachen unnötig für ein Beispiel.

Verwandte Themen