天天看點

Roson講Qt#43 QML顔色動畫ColorAnimation1.繼承關系2.綜述3.資料成員

1.繼承關系

父類:PropertyAnimation

子類:無

2.綜述

ColorAnimation是一個專門的PropertyAnimation,它定義了當顔色值改變時應用的動畫。

下面是一個應用于矩形顔色屬性的ColorAnimation作為屬性值源。它将顔色屬性的值從目前值動畫為“red”,時間超過1000毫秒:

import QtQuick 2.0

  Rectangle {
      width: 100; height: 100
      color: "red"

      ColorAnimation on color { to: "yellow"; duration: 1000 }
  }
           

與任何其他動畫類型一樣,ColorAnimation可以通過多種方式應用,包括過渡、行為和屬性值源。Qt Quick文檔中的動畫和過渡顯示了建立動畫的各種方法。

為友善起見,當在過渡中使用ColorAnimation時,它将使在狀态改變期間修改過的任何顔色屬性動畫。如果為動畫顯式設定了一個或多個屬性,那麼将使用這些屬性。

更多資訊可查閱 Animation and Transitions in Qt Quick and Qt Quick Examples - Animation.

3.資料成員

3.1 from : color

此屬性儲存動畫開始時的顔色值。

例如,以下動畫在顔色值達到“#c0c0c0”時才應用:

  Item {
      states: [
          // States are defined here...
      ]

      transition: Transition {
          ColorAnimation { from: "#c0c0c0"; duration: 2000 }
      }
  }
           

如果ColorAnimation是在Transition或Behavior中定義的,則該值預設為Transition的開始狀态中定義的值,或行為觸發時屬性的目前值。

更多資訊可查閱 Animation and Transitions in Qt Quick.

3.2 to : color

此屬性儲存動畫結束時的顔色值。

如果ColorAnimation是在Transition或Behavior中定義的,則該值預設為Transition的結束狀态中定義的值,或觸發Behavior的屬性更改的值。

更多資訊可查閱 Animation and Transitions in Qt Quick.

繼續閱讀