Display a OpenGL QWindow in QML



  • Hello good people

    I have a QML main file

    @Rectangle {
    id: root
    width: 640
    height: 480
    color: "#fff396"

    property int margin: 10
    MenuHybrid{ // this is just a QML menu with QML buttons
        id: menu
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.margins: margin
    }
    

    //How to display a QWindow class with Opengl in replace of this black rectangle ???
    Rectangle {
    id: drawingBoard
    color: "black"

        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        anchors.top: menu.bottom
        anchors.margins: margin
    }
    

    }
    @

    I have added to the project a c++ QWindow class, I don't know how to display it in QML.
    I've read the docs about the QML and C++ integration, but still haven't figure out weel the logic.
    Basically I want to achieve a fancy QML paint application, with a menu with buttons and QGLWidget area, so the user draws stuff with mouse clicks. Since QGLWidgets is not recommended for QML app, I believe, I'm thinking of a QWindow class.
    Thanks


  • Moderators

    QGL* stuff is pretty much deprecated, consider moving to QOpenGL* classes instead.

    And: every QML Item is an OpenGL painter, so you can also think about subclassing QQuickItem (OpenGL, you need to push the result into a texture to have it drawn) or QQuickPaintedItem (uses QPainter!).

    I'm far from being an expert here, though. Would be nice if others joined in.



  • You can look my example "project":https://github.com/nexelen/Qt5OpenGLStudy .


Log in to reply
 

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