- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
内部MouseArea
首先获取鼠标事件。我想“看到”这些事件,以便设置各种属性,但不影响它们。我希望鼠标事件传播到任何父 MouseArea
。
考虑这段代码。我想单击蓝色方 block 来查看“蓝色按下”和“蓝色释放”以及传递给“父级按下”和“父级释放”。
如果我接受该事件,家长不会收到它。如果我不接受按下,那么我看不到释放。
import QtQuick 2.7
import QtQuick.Controls 1.4
ApplicationWindow
{
visible: true
width: 800
height: 1024
Rectangle
{
anchors.fill: parent
color: "yellow"
MouseArea
{
// i want these to happen even when mouse events are in the
// blue square
anchors.fill: parent
onPressed: console.log("parent pressed");
onReleased: console.log("parent released");
}
Rectangle
{
x: 100
y: 100
width: 100
height: 100
color: "blue"
// i would like to "see" events, but not affect them
// i want all mouse events to pass to parent, as if i am not here.
// however, not accepting "pressed" means i don't see "released"
MouseArea
{
anchors.fill: parent
onPressed:
{
console.log("blue pressed");
mouse.accepted = false
}
onReleased:
{
console.log("blue released");
mouse.accepted = false
}
}
}
}
}
欢迎提出想法。谢谢,
最佳答案
如果 propagateComposedEvents
设置为 true,则组合事件将自动传播到场景中同一位置的其他 MouseAreas
。每个事件都会按照堆叠顺序传播到其下方下一个启用的 MouseArea
,并沿着该视觉层次结构向下传播,直到 MouseArea
接受该事件。一旦事件沿着层次结构向下移动,它就无法向上移动,直到另一个鼠标事件发生。因此,当您在蓝色矩形中设置 mouse.accepted = false
时,鼠标事件将转到黄色矩形,并接收 pressed
和 released
> 信号,但上部矩形将不再接收任何事件,直到另一个鼠标事件发生。所以,答案是否定的。
如果您想要处理不同级别的鼠标事件,例如您希望一个 MouseArea
处理 clicked
信号,另一个处理 pressAndHold
>,或者如果您希望一个 MouseArea
大部分时间处理 clicked
,但在满足某些条件时传递它,以下示例会有所帮助
import QtQuick 2.0
Rectangle {
color: "yellow"
width: 100; height: 100
MouseArea {
anchors.fill: parent
onClicked: console.log("clicked yellow")
}
Rectangle {
color: "blue"
width: 50; height: 50
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
onClicked: {
console.log("clicked blue")
mouse.accepted = false
}
}
}
}
关于qt qml。 MouseArea 可以看到事件,但将它们全部传递给父级而不影响它们吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505727/
我查看了类似的线程,但没有太大帮助。 我正在使用 QtQuick.Controls.Button在 QML将鼠标悬停在按钮上时,我无法更改光标形状!我想在不使用 MouseArea 的情况下实现这一点
以下代码生成一个白色矩形,其中包含一个红色矩形和一个灰色矩形。每个矩形都有一个关联的 MouseArea。当在其中单击鼠标时,灰色矩形变为蓝色。红色矩形在鼠标光标进入其中时打印一条控制台消息,在发出释
我正在使用 MouseArea 实现手势捕捉器(向左/向右滑动)。它应该在具有垂直 flickableDirection 的 Flickable 内工作。此外,它应该以视觉堆栈顺序将鼠标事件传播到它下
如果我放一个 MouseArea在 QML 元素上,然后 MouseArea将窃取所有鼠标事件。 因此,TextEdit将是不可编辑和不可选择的。 TextEdit { // some pro
是否可以传播 MouseArea的 positionChanged 事件到基础事件? 我试图设置 mouse.accepted至 false对于最顶层 MouseArea 的任何现有信号处理程序以及设
内部MouseArea首先获取鼠标事件。我想“看到”这些事件,以便设置各种属性,但不影响它们。我希望鼠标事件传播到任何父 MouseArea。 考虑这段代码。我想单击蓝色方 block 来查看“蓝色按
有一个 QQuickPaintedItem 带有重载的鼠标事件处理程序: void Plotter::mousePressEvent(QMouseEvent *event) { qDebug(
如何从鼠标区域获取鼠标的绝对位置?我需要让它显示正确位置的弹出窗口 Item { Menu { id: menu MenuItem {
我想在 QML 中实现以下场景。 这是 ListView 的示例/简化委托(delegate)元素: Component { Item { id: container
我有一个在 QML 中声明的 ChartView 项,我需要类似橡皮筋的缩放功能。这可以通过半透明矩形和 MouseArea 项目来实现。问题是对于一个矩形,它只能选择从左上角到右下角的区域,因为带有
我有一个在 QML 中声明的 ChartView 项,我需要类似橡皮筋的缩放功能。这可以通过半透明矩形和 MouseArea 项目来实现。问题是对于一个矩形,它只能选择从左上角到右下角的区域,因为带有
我有以下代码: ListView { delegate: MyDelegate { MouseArea { anchors.fill: parent
在 Android 上测试应用程序时,我注意到发生了一些奇怪的事情。双击事件处理程序已触发,但该特定项目没有发生任何双击。 试图隔离这个问题,我发现几乎每一个点击链都像双击一样快速,不管两个对象会导致
我遇到了问题,如何在 qml 中检测通过 MouseArea 的滑动? 此代码,来自文档: Rectangle { id: container width: 600; heig
我在 QT QML 中创建了一个项目,其中包含一个 MouseArea 元素。 这是代码, import QtQuick 1.0 Rectangle { id: base width: 240 hei
我正在使用 qt quick controls 2 SplitView,似乎 SplitView 项内的任何 MouseArea 都将鼠标事件从SplitView 句柄。这意味着当 handle 位于
摘要:如何在不硬编码尺寸的情况下将图标粘贴在文本旁边,并将它们都包装在 MouseArea 中......以一种可行的方式在 GridLayout 内? 我创建了一个 QML 布局,其中在可点击的“按
import QtQuick 2.2 import QtQuick.Window 2.1 import QtQuick.Controls 1.1 ApplicationWindow { fla
我正在尝试将 MouseArea 鼠标事件与 C++ 连接,但是 QQuickMouseArea 是私有(private)的,所以我无法获取信号。 像这样: QObject::connect(mous
有一个 TextArea,我已将 activeFocusOnPress 属性设置为 false 以阻止虚拟键盘弹出,但是当用户单击 TextArea 时,光标位置应该移动。为了实现这一目标,我认为 m
我是一名优秀的程序员,十分优秀!