GlWidgets interfere with each other

  • I have a stacked widget in mainwindow with a second stacked widget on the second page of the mainwindow stackedwidget.

    On the first page (of that second stacked widget) there is a glwidget for viewing objects in 3D;
    On the second page there is a glwidget for viewing objects in 2D;

    I made two widgets and promoted them to glwidgets...

    Now they seem to share the same matrix stack;
    when I call the modelview/projection matrices the other widget gets changed as well.

    There are 2 pushbuttons to change between the 3D and 2D view, the problem is that resizeGL doesn't get called every time so the view is distorted when i switch.

    I thought I could make a second resize funct give it the width() and height() and call it when the pushbutton to change between the views gets pressed.
    Well the funct works but the widget doesn't take mouse input until i resize the window.

    Is there a way to separate the widgets completely?

    This is the first widget
    GLWidget::GLWidget(QWidget *parent) :

    connect (&timer,SIGNAL(timeout()),this,SLOT(updateGL()));


    This the second one
    @GLWidget2D::GLWidget2D(QWidget *parent) :

    connect (&timer2D,SIGNAL(timeout()),this,SLOT(updateGL()));


    Of course there is more code .

  • Just a guess, but it sounds like the OpenGL context of the two widgets isn't getting set correctly. Why don't you add a makeCurrent() to both glwidget's various methods to make sure commands executed in one glwidget are not sent to the other's context on the graphics card?

  • Thank you for your reply

    I tried makeCurrent but I didn't notice any effect
    I guess I did it wrong.

    This gets called when I press the "3D" pushbutton
    @void MainWindow::ChangeToGL3DPage(){



    Tried all that

    To no avail

    Then I added in the resizefunctions
    if (isEnabled());
    now it works fine
    makeCurrent seems to be per thread

    Since I'm a noob threading isn't for me yet
    I guess this is why it didn't work

Log in to reply

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