【问题标题】:Create an opacity animation in QML在 QML 中创建不透明动画
【发布时间】:2016-08-20 18:54:44
【问题描述】:

我有一个不透明度为 90% 的灰色矩形,我正在尝试使用动画更改此不透明度。我尝试过使用 OpacityAnimator,但正如文档所述,Item::opacity 的值在动画完成后更新

这不是我所期望的,我想在动画期间降低不透明度,而不是在 2 秒后立即将其从 90 更改为 0。

这就是我所拥有的:

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("title")
    Rectangle{
        width: parent.width
        height: parent.height
        opacity: 90
        color: "gray"
        id: recLoading
        Text {
            id: txtLoading
            text: qsTr("Loading")
            font.bold: true
        }

        OpacityAnimator on opacity{
            from: 90
            to:0
            duration:2000
            target: parent
            running:true
        }

    }
}

【问题讨论】:

    标签: qt qml qtquick2


    【解决方案1】:

    不透明度指定为介于 0.0(完全透明)和 1.0(完全不透明)之间的数字。

    http://doc.qt.io/qt-5/qml-qtquick-item.html#opacity-prop

    【讨论】:

      【解决方案2】:

      尝试将不透明度值更改为介于 0 和 1 之间的值,即

      ...
      Rectangle{
          width: parent.width
          height: parent.height
          opacity: 0.9
          ...
      
      OpacityAnimator on opacity{
          from: 0.9
          to: 0.0
          duration:2000
          target: parent
          running:true
      }
      

      【讨论】:

      • 哦,我还以为是0到100之间呢!现在它正在工作!谢谢:D
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 2010-09-25
      • 2011-03-24
      • 2012-08-26
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多