qt - QML 数字动画 : setRunning() cannot be used on non-root animation nodes

标签 qt popup qml

我的代码在这里:

MyPopup.qml:

import QtQuick 2.0
import QtQuick.Window 2.3
import QtQuick.Controls 2.2

Popup {
  id: popup
  width: 250
  height: 250
  closePolicy: Popup.NoAutoClose
  y: -300

  background: Rectangle {
    anchors.fill: parent
    color: '#3f3f3f'
    opacity: 15
    Text {
      text: 'HELLO WORLD!'
      color: 'white'
      font.pointSize: 20
      anchors.centerIn: parent
    }

    Button {
      anchors.bottom: parent.bottom
      text: 'Close Popup'
      onClicked: popup.close()
    }
  }

  enter: Transition {
    NumberAnimation {
      target: parent
      property: 'y'
      to: (Screen.height / 2) - (height / 2)
      duration: 400
      running: true
    }
  }

  exit: Transition {
    NumberAnimation {
      target: parent
      property: 'y'
      to: -((Screen.height / 2) - (height / 2))
      duration: 400
      running: true
    }
  }
}

我在 main.qml 中放了一个按钮。当我单击该按钮时,popup.open() 正在运行。我在 MyPopup.qml 中放置了一个按钮,当我单击该按钮时,popup.close() 正在运行。当我点击按钮时,我的应用程序卡住并关闭。

我收到以下警告: qrc:/MyPopup.qml:31:5: QML NumberAnimation: setRunning() 不能用于非根动画节点。
qrc:/MyPopup.qml:41:5: QML NumberAnimation: setRunning() 不能用于非根动画节点。

最佳答案

documentation ,给出了两个例子,但没有一个例子有 running 属性实例化。 enter 属性示例:

Popup {
    enter: Transition {
        NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
    }
}

对于 exit 属性:

Popup {
    exit: Transition {
        NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
    }
}

我在没有 running: true 行的情况下尝试了您的代码并且它有效。因此,当 popup.open()popup.exit() 被调用时,转换就会运行。

关于qt - QML 数字动画 : setRunning() cannot be used on non-root animation nodes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48895953/

相关文章:

qt - QtWebEngine 时是否允许使用 WebRTC 网络摄像头请求?

c++ - Qt5.4.1升级到5.12.1,现在QCodec报异常

javascript - 如何在同一窗口和同一选项卡中打开 URL

javascript - 在 IE 中打开弹出窗口 - "Member not found"

html - 我想让我的弹出式 div 固定到这个地方

qt - 奇怪的 alpha 混合结果与 ShaderEffectItem

python-3.x - 如何将 PyQt5 pyqtSlot 连接到 QML ListView 信号 "activated"?

c++ - QTreeView 禁用悬停在行上的突出显示

c++ - 私有(private)成员的 QT/C++ 类声明对构造函数不可见?

c++ - UDP 加密 - 简单且安全