Important: Please read the Qt Code of Conduct -

OpenGL and QML overlapping

  • Hello there!

    I am currently developing some tool with Qt 5.3 and QtQuick 2, trying to implement an OpenGL control.
    My template was the "Scene Graph - OpenGL Under QML": Example. It worked really well until i discovered a strange thing:

    Normal QML components appear to overlap any of my OpenGL drawings which is kinda obstructive if i want to contain my OpenGL rendered thing in the scene graph before other objects.

    Has anyone encountered similar behaviour and if yes, is there a fix for this?

  • Moderators


    Try to set a lower Z value to the QML components.

  • Hey, i just tried to lower the Z values but no success.
    Here is my QML test source and the resulting image:

    @import QtQuick 2.0
    import OpenGLUnderQML 1.0

    Item {

    width: 320
    height: 480
    Rectangle {
        z: -1
        color: Qt.rgba(1, 1, 1, 0.7)
        radius: 10
        border.width: 1
        border.color: "white"
        anchors.fill: label
        anchors.margins: -10
    Squircle {
        z: 1
        SequentialAnimation on t {
            NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
            NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
            loops: Animation.Infinite
            running: true
    Text {
        z: -1
        id: label
        color: "black"
        wrapMode: Text.WordWrap
        text: "The background here is a squircle rendered with raw OpenGL using the 'beforeRender()' signal in QQuickWindow. This text label and its border is rendered using QML"
        anchors.right: parent.right
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.margins: 20


    ! Image)!

  • Moderators

    The first 2 paragraphs "here": might answer your questions.

  • Sometimes a good RTFM is the right hint :P
    Thanks, it should work now!

Log in to reply