gpt4 book ai didi

c++ - 将鼠标事件发送到虚拟现实 OpenGL 场景中的 QtQuick 窗口

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:44:39 26 4
gpt4 key购买 nike

我目前正在从事一个基于 OpenGL 的虚拟现实项目。因为我还需要某种形式的用户界面,所以我认为将 QtQuick 窗口集成到场景中是个好主意。将窗口绘制到纹理上没有问题(我使用了 this example )但是我很难发送鼠标事件以便我的 Controller 可以与之交互。

Here is a quick example video on YouTube.在此示例中,只要我将鼠标悬停在嵌入的 GIF 上,它的动画就会停止。这在普通 QML 应用程序中有效,但在我手动发送 MouseMove 事件时无效。窗口内的鼠标位置是已知的(视频中的红线表示交叉点),我目前正在通过

发送事件
QQuickWindow::sendEvent(QQuickItem* item, QEvent*)

其中 item 是 qml 源中的根 Rectangle:

import QtQuick 2.3
import QtQuick.Controls 2.0

Rectangle {
color: mouseArea.containsMouse ? "red" : "white"
width: 600
height: 400

MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true

AnimatedImage {
anchors.fill: parent
paused: mouseArea.containsMouse
source: "test.gif"
}
}
}

每次找到光线和窗口之间的交点时我发送的事件是通过以下方式完成的:

QMouseEvent* mouseMoveEvent = new QMouseEvent(
QEvent::MouseMove, // wrong event?
cursorPosition, cursorPosition, // Note: cursorPosition := the calculated cursor coordinates within the window
Qt::MouseButton::NoButton,
Qt::MouseButtons(), // is this right?
Qt::KeyboardModifier::NoModifier);
window->sendEvent(rootItem, mouseMoveEvent); // Note: window is my QQuickWindow, rootItem is the root Rectangle

我不是 QML 方面的专家(很少使用它),如果有人对如何解决这个问题有建议,我将不胜感激。我的猜测是,我既没有使用正确的事件也没有正确发送它们。

最佳答案

我自己找到了解决方案。而不是使用 QQuickWindow::sendEvent(..) 我不得不简单地使用 QApplication()::instance()->sendEvent(..)。

关于c++ - 将鼠标事件发送到虚拟现实 OpenGL 场景中的 QtQuick 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41397038/

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