Sending mouse events to a QtQuick window in a OpenGL scene



  • Hello,

    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 am struggling to send mouse events so that my controllers can interact with it.

    Here is a quick example video on YouTube.
    The mouse position within the window is known (the red line in the video indicates an intersection) and I am currently sending a MouseMove 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 I am sending 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.



  • The solution was to simply use QApplication()::instance()->sendEvent(..) instead of QQuickWindow::sendEvent(..).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.