我的代码在这里:
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/