gpt4 book ai didi

mouse - 将鼠标事件发送到 QML 对象

转载 作者:行者123 更新时间:2023-12-02 11:17:20 25 4
gpt4 key购买 nike

我需要从 QML 向 QML 对象发送鼠标事件。例如,

Rectangle
{
id: rect
MouseArea
{
anchors.fill: parent
onClicked: console.log(mouse.x + ', ' + mouse.y)
}

Rectangle
{
x: 0; y: 0; width: 50; height: 50
color: 'red'
onClicked: rect.click(randomX(), randomY()) // <---- HERE
}
}

我希望标记为“HERE”的行引发 rect 的点击事件,该事件将被传递到 MouseArea

最佳答案

你的问题和this question之间似乎有某种关系

请看一下。

import QtQuick 1.0

Rectangle {
width: 360
height: 360

MouseArea {
anchors {fill: parent; margins: 40}
onClicked: console.log("hello from below");
}

MouseArea {
id: mouseArea
anchors.fill: parent

onClicked: {
console.log("hello from top")
forwardEvent(mouse, "clicked");
}

function forwardEvent(event, eventType) {
mouseArea.visible = false
var item = parent.childAt(event.x, event.y)
mouseArea.visible = true
if (item && item != mouseArea && typeof(item[eventType]) == "function") {
item[eventType](event);
}
}
}
}

关于mouse - 将鼠标事件发送到 QML 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8721154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com