Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGLWidget in QMdiSubWindow
Qt 6.11 is out! See what's new in the release blog

QGLWidget in QMdiSubWindow

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skalimer0
    wrote on last edited by
    #1

    I make a simple project base on the tutorial example "Boxes" : I put the QGLWidget in a QMdiWindow to have multiple windows.

    @
    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);

    QMdiArea *zoneCentrale = new QMdiArea();
    zoneCentrale->show();

    // CREATION SUBWINDOW based on "Boxes" Tutorial

    QMdiSubWindow *sub1 = new QMdiSubWindow(zoneCentrale);
    int maxTextureSize = 1024;

    QGraphicsScene *scene = new QGraphicsScene(0,0,200,200,sub1);
    QGraphicsView *vue = new QGraphicsView(scene,sub1);
    QGLWidget *widget1 = new QGLWidget(QGLFormat(QGL::SampleBuffers));
    widget1->makeCurrent();

    if (!necessaryExtensionSupported()) {
    QMessageBox::critical(0, "OpenGL features missing",
    "The OpenGL extensions required to run this demo are missing.\n"
    "The program will now exit.");
    delete widget1;
    }

    // Check if all the necessary functions are resolved.
    if (!getGLExtensionFunction().resolve(widget1->context())) {
    QMessageBox::critical(0, "OpenGL features missing",
    "Failed to resolve OpenGL functions required to run this demo.\n"
    "The program will now exit.");
    delete widget1;
    }

    widget1->makeCurrent(); // The current context must be set before calling Scene's constructor
    Scene scene_1(1024, 768, maxTextureSize);
    vue->setViewport(widget1);
    vue->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    vue->setScene(&scene_1);
    sub1->setWidget(vue);
    sub1->show();

    // END CREATION SUBWINDOW

    return app.exec();

    }
    @

    This code compile and work fine, but if i put the code used to create the subwindow in a function (to create multiple subwindow) : the subwindow is created but will not be refreshed when i'll run my project.

    I don't understand... it's exactly the same code (copy/cut)

    If anyone have an idea...
    Thanks.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      melghawi
      wrote on last edited by
      #2

      Can you post the code that uses a separate function for sub window creation?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skalimer0
        wrote on last edited by
        #3

        Like i said... just copy/cut :

        @
        QMdiSubWindow *createSubWindow(QMdiArea *zone) {
        QMdiSubWindow *sub1 = new QMdiSubWindow(zone);
        int maxTextureSize = 1024;

        QGraphicsScene *scene = new QGraphicsScene(0,0,200,200,sub1);
        QGraphicsView *vue = new QGraphicsView(scene,sub1);
        QGLWidget *widget1 = new QGLWidget(QGLFormat(QGL::SampleBuffers));
        widget1->makeCurrent();

        if (!necessaryExtensionSupported()) {
        QMessageBox::critical(0, "OpenGL features missing",
        "The OpenGL extensions required to run this demo are missing.\n"
        "The program will now exit.");
        delete widget1;
        }

        // Check if all the necessary functions are resolved.
        if (!getGLExtensionFunction().resolve(widget1->context())) {
        QMessageBox::critical(0, "OpenGL features missing",
        "Failed to resolve OpenGL functions required to run this demo.\n"
        "The program will now exit.");
        delete widget1;
        }

        widget1->makeCurrent(); // The current context must be set before calling Scene's constructor
        Scene scene_1(1024, 768, maxTextureSize);
        vue->setViewport(widget1);
        vue->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
        vue->setScene(&scene_1);
        sub1->setWidget(vue);
        return sub1;
        }

        int main(int argc, char **argv)
        {
        QApplication app(argc, argv);

        QMdiArea *zoneCentrale = new QMdiArea();
        zoneCentrale->show();

        QMdiSubWindow *sub = creationSubWindow(zoneCentrale);
        sub->show();

        return app.exec();

        }
        @

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved