2017-01-06 2 views
0

Я хочу установить полноэкранное приложение на один из моих экранов, поэтому мне нужно установить его высоту, ширину, x, y и так далее. Однако я обнаружил, что анимация не работает.Почему моя анимация не работает в QML?

Я когда-либо думал, что это вызвано тем, что я установил его на один целевой экран, поэтому я создаю тестовый код, здесь я жестко кодирую 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.") 
      } 
     } 
    } 


} 
+0

У вас хороший код, но вы забыли указать свойство, которое хотите оживить. – folibis

ответ

1

Потому что вы ничего не анимировать. Вам нужно указать цель.

Просто дикая догадка, но вы, вероятно, хотите оживить высоту?

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

Смотрите комментарии, для того, что я сделал. И я разделил ваш код на некоторые ненужные вещи для примера.

Смежные вопросы