Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Mouse events in QML rendered using QQuickRenderControl



  • Greetings,
    I have tried to implement QML rendering into QOffscreenSurface and using this as a texture in OpenGL (same as example provided by Qt). I am also trying to implement mouse events so that if a user clicks on the QML interface it will respond (I have tried the QML with ToggleButton and some buttons that change the text color in a Text). I am using

    void UIRenderer::mousePress(double x,double y)
    {
        QPointF pos(x*WINDOW_WIDTH,y*WINDOW_HEIGHT);
        QMouseEvent mappedEvent(QEvent::MouseButtonPress, pos, Qt::MouseButton::LeftButton, Qt::MouseButton::LeftButton, Qt::NoModifier);
        QCoreApplication::sendEvent(m_quickWindow, &mappedEvent);
    }
    
    void UIRenderer::mouseRelease(double x,double y)
    {
        QPointF pos(x*WINDOW_WIDTH,y*WINDOW_HEIGHT);
        QMouseEvent mappedEvent(QEvent::MouseButtonRelease, pos, Qt::MouseButton::LeftButton, Qt::MouseButton::LeftButton, Qt::NoModifier);
        QCoreApplication::sendEvent(m_quickWindow, &mappedEvent);
    }
    

    where x = [0..1] and y = [0..1] represent mouse event location. The problem is that when I click on some button and then I click on some other buttons the first clicked button responds (regardles of where the click event occured). I am certain that I missed something. Could you please help?

    Thank you.



  • @LoneWolf10
    Could you post some minimal working example for others to test out?


Log in to reply