QML Qt5 中 onEntered 和 onExited 的可翻转问题
Flipable issue with onEntered and onExited in QML Qt5
我试图改变这里给出的例子(http://qt-project.org/doc/qt-4.8/qml-flipable.html)以获得相同的效果。碰巧当我用鼠标在前面进入时,信号 onEntered 和 onExited 被捕获了几次: 例如:将鼠标递过,出现在控制台上:
进入 退出 进入
如果鼠标步过非常快,则执行翻转,但即使鼠标不再处于该区域,也会保持第二种状态。帮助?
Flipable {
id: flipable
width: 240
height: 240
property bool flipped: false
front: Rectangle {
color: "red";
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
onEntered: {
console.log("Entered");
flipable.flipped = !flipable.flipped
}
}
}
back: Rectangle {
source: "blue";
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
onExited: {
console.log("Exited");
flipable.flipped = !flipable.flipped
}
}
transform: Rotation {
id: rotation
origin.x: flipable.width/2
origin.y: flipable.height/2
axis.x: 0; axis.y: 1; axis.z: 0
angle: 0
}
states: State {
name: "back"
PropertyChanges { target: rotation; angle: 180 }
when: flipable.flipped
}
transitions: Transition {
NumberAnimation { target: rotation; property: "angle"; duration: 1000 }
}
}
首先,我必须责怪你,因为你的例子不起作用。
好的,所以不要将鼠标区域放在前后,因为它们的宽度是动态变化的,边框会接触鼠标,从而产生进入和退出的信号。必须将鼠标区域设置为父级或同级。然后,您可以使用输入和退出的信号或包含鼠标属性。
import QtQuick 2.0
MouseArea
{
id: mouseArea
width: 240
height: 240
hoverEnabled: true
onEntered:
{
console.log("Entered");
flipable.flipped = !flipable.flipped
}
onExited:
{
console.log("Exited");
flipable.flipped = !flipable.flipped
}
Flipable
{
id: flipable
width: 240
height: 240
property bool flipped: false
//property bool flipped: mouseArea.containsMouse // uncoment if onEntered and onExited is commented
front: Rectangle
{
color: "red";
anchors.fill: parent
}
back: Rectangle
{
color: "blue";
anchors.fill: parent
}
transform: Rotation
{
id: rotation
origin.x: flipable.width/2
origin.y: flipable.height/2
axis.x: 0; axis.y: 1; axis.z: 0
angle: 0
}
states: State
{
name: "back"
PropertyChanges { target: rotation; angle: 180 }
when: flipable.flipped
}
transitions: Transition
{
NumberAnimation { target: rotation; property: "angle"; duration: 1000 }
}
}
}
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- QML Qt5 中 onEntered 和 onExited 的可翻转问题