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) :
    QGLWidget(parent)
    {

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

    }
    ....
    @

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

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

    }....@

    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(){

    ui->GL2D3DstackedWidget->setCurrentIndex(0);
    
    Show2D=0;
    Show3D=1;
    UpdateView();
    
      ui->glWidget3D->makeCurrent();
      ui->glWidget2D->doneCurrent();
     ui->glWidget2D->setDisabled(1);
     ui->glWidget3D->setEnabled(1);   
     ui->glWidget3D->isEnabled();
    ui->glWidget3D->show();
    ui->glWidget3D->adjustSize();
    ui->glWidget3D->update();
    ui->GL2D3DstackedWidget->currentWidget()->update();
    

    }@

    Tried all that

    To no avail

    Then I added in the resizefunctions
    if (isEnabled());
    now it works fine

    https://qt-project.org/forums/viewthread/9052
    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.