Congratulations to our 2022 Qt Champions!

QML/OpenGL in ApplicationWindow

  • I'm trying to integrate a C++/OpenGL QML component as a subwindow within the content area of an ApplicationWindow (QtQuickControls 5.3). This work is based on the "OpenGL Under QML" example in QT 5.3.1. My OpenGL rendering (3D Terrain) is working as expected, but the placement of the OpenGL viewport is affected by the height of the status bar as shown in the screenshots. This is causing problems when various views (QML, QPainter, OpenGL) with fixed size and position are loaded dynamically and widgets are anchored to the bottom of the view. This seems to be a internal problem, but maybe I'm missing something. Any help would be appreciated.

    (no statusbar)
    ! statusbar)!

    (with statusbar)
    ! status bar)!

    @ApplicationWindow {
    visible: true
    id: appwin
    toolBar: BorderImage {
    id: toolbar
    width: parent.width
    height: 80
    source: "qrc:/images/toolbar.png"
    statusBar: StatusBar {
    id: status
    height: 100
    width: parent.width/2
    height: parent.height
    anchors.left: parent.left
    width: 512
    height: 512
    anchors.centerIn: parent
    Rectangle {
    width: 512
    height: 512
    anchors.centerIn: parent
    color: Qt.rgba(1, 0, 0, 0.5)

    Relevant C++ code to setup viewport:
    @mWidth = mItem->width();
    mHeight = mItem->height();
    QPoint pt = mItem->window()->mapToGlobal(QPoint(0,0));
    mX = pt.x();
    mY = pt.y();
    glViewport(mX, mY, mWidth, mHeight);
    glScissor(mX, mY, mWidth, mHeight);

    glClearColor(0.0f, 0.4f, 0.0f, 1.0f);

Log in to reply