Qt QML NumberAnimation:setRunning()不能在非根动画节点上使用
我的代码在这里:Qt QML NumberAnimation:setRunning()不能在非根动画节点上使用,qt,popup,qml,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: '
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()不能在非根动画节点上使用。
中,给出了两个示例,其中没有一个示例实例化了running
属性。enter
属性示例:
Popup {
enter: Transition {
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
}
}
Popup {
exit: Transition {
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
}
}
对于退出
属性:
Popup {
enter: Transition {
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
}
}
Popup {
exit: Transition {
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
}
}
我在没有运行的情况下尝试了你的代码:true
行,结果成功了。因此,当调用popup.open()
或popup.exit()
时,转换就会运行