QGLWidget in QMdiSubWindow



  • 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.



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



  • 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();

    }
    @


Log in to reply
 

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