Reputation: 81
I am currently working on a virtual reality project that builds on OpenGL. Because I also needed some form of user interface, I thought it would be a good idea to integrate QtQuick windows into the scene. Drawing the window to a texture works without problems (I used this example) but I struggle to send mouse events so that my controllers can interact with it.
Here is a quick example video on YouTube. In this example, the animation of the embedded GIF should stop whenever I hover over it. This works in a normal QML application but not when I manually send a MouseMove event. The mouse position within the window is known (the red line in the video indicates an intersection) and I am currently sending the event through
QQuickWindow::sendEvent(QQuickItem* item, QEvent*)
where item is the root Rectangle in the qml source:
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"
}
}
}
The event, which I send every time an intersection between the ray and the window is found, is done with:
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
I am not an expert in QML (rarely used it) and would appreciate it if someone has suggestions on how to solve this. My guess is, that I am neither using the right event nor correctly sending them.
Upvotes: 4
Views: 1014
Reputation: 81
I found a solution myself. Instead of using QQuickWindow::sendEvent(..) I had to simply use QApplication()::instance()->sendEvent(..).
Upvotes: 4