我想知道如何在QML中进行图像源之间的平滑过渡
import QtQuick 1.1
Image {
id: rect
source: "quit.png"
smooth: true
MouseArea {
id: mouseArea
anchors.fill: parent
anchors.margins: -10
hoverEnabled: true //this line will enable mouseArea.containsMouse
onClicked: Qt.quit()
}
states: State {
name: "mouse-over"; when: mouseArea.containsMouse
PropertyChanges { target: rect; scale: 0.8; source :"quit2.png" }
}
transitions: Transition {
NumberAnimation { properties: "scale, source"; easing.type: Easing.InOutQuad; duration: 1000 }
}
}
Run Code Online (Sandbox Code Playgroud)
但它不像源代码那样在源上作为最终的状态变化而工作.所以我想知道如何使一个图像源淡入其他和后退?
你想让第一张图片淡出到另一张图片中吗?如果将两个Image
对象放在彼此之上,然后为该opacity
属性设置动画,该怎么办?
编辑:这对我有用(我使用QtQuick 1.0,因为我的Qt Creator安装有点过时):
import QtQuick 1.0
Rectangle {
Image {
id: rect
source: "quit.png"
smooth: true
opacity: 1
MouseArea {
id: mouseArea
anchors.fill: parent
anchors.margins: -10
hoverEnabled: true //this line will enable mouseArea.containsMouse
onClicked: Qt.quit()
}
states: State {
name: "mouse-over"; when: mouseArea.containsMouse
PropertyChanges { target: rect; scale: 0.8; opacity: 0}
PropertyChanges { target: rect2; scale: 0.8; opacity: 1}
}
transitions: Transition {
NumberAnimation { properties: "scale, opacity"; easing.type: Easing.InOutQuad; duration: 1000 }
}
}
Image {
id: rect2
source: "quit2.png"
smooth: true
opacity: 0
anchors.fill: rect
}
}
Run Code Online (Sandbox Code Playgroud)
对于评论中的问题:您可以通过复制锚点将图像准确地放在另一个上面 anchors.fill: rect