这可能是一个错误,但请继续阅读:
在以下代码中,当可翻转翻转(但反转)时,可翻转正面的鼠标区域保持活动状态,甚至从背面接管一些鼠标区域:
import QtQuick 2.0
Rectangle {
height: 500
width: 500
Flipable {
id: flipable
anchors.fill:parent
property bool flipped: false
front: Rectangle{
color: "black"
anchors.fill: parent
Rectangle {
color:"darkgrey"
height: parent.height / 2
width: parent.width / 2
MouseArea {
anchors.fill: parent
onClicked: flipable.flip()
}
}
}
back: Rectangle {
id: yellow
color: "yellow"
anchors.fill: parent
MouseArea {
anchors.fill: parent
onClicked: yellow.color = "green"
}
}
transform: Rotation {
id: rotation
origin.x: flipable.width/2
origin.y: flipable.height/2
axis.x: 0; axis.y: 1; axis.z: 0 // set axis.y to 1 to rotate around y-axis
angle: 0 // the default angle
}
states: State {
name: "back"
PropertyChanges { target: rotation; angle: 180 }
when: flipable.flipped
}
transitions: Transition {
NumberAnimation { target: rotation; property: "angle"; duration: 400 }
}
function flip () {
flipped = !flipped
}
}
}
当您按下灰色区域时页面会翻转,如果再次按下(现在它位于右侧的后面),它会再次翻转。正确的行为是黄色方块变为绿色,即使单击右上角也是如此。
谢谢!