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. QWidget::repaint: Recursive repaint detected
Forum Update on Monday, May 27th 2025

QWidget::repaint: Recursive repaint detected

Scheduled Pinned Locked Moved Unsolved General and Desktop
qopenglwidgetqpainterpainteevent
3 Posts 2 Posters 3.6k Views
  • 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.
  • Mostafa WasatM Offline
    Mostafa WasatM Offline
    Mostafa Wasat
    wrote on last edited by
    #1

    Hello, I'm working on a visualization application using Qt5.5, The application contains a QOpenGLWidget that uses QOpenGLFunctions_3_2_Core, everything was working fine using (initializeGL() , paintGL() , and resizeGL() ) functions.

    Now, the time has come where i need to draw some text (just simple text nothing fancy) on the openglwidget, I figured that I would simply reimplement my widget using paintEvent() function instead of paintGL(). And so I did, I renamed paintGL() to updateGL() and added paintEvent() function as follows:

    void OpenGLWidget::paintEvent(QPaintEvent *e){
        Q_UNUSED(e);
        updateGL();
    
        QPainter p(this);
        p.setPen(Qt::white);
        p.drawText(100 ,100, "Test");
        p.end();
    }
    

    However running this outputs a runtime error/warning (QWidget::repaint: Recursive repaint detected) and the text is not drawn, However the opengl scene is rendered correctly. Also, The menu bar on the mainwindow doesn't get drawn once the application starts, hovering over the menus locations or simply hiding/showing the app draws them.

    I tested the same code on a Qt Example (HelloGL2), and it runs fine and the text appears where it should.

    How can I know what causes this error? or where can i find more information about this specific error?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I guess updateGL() call causes paintEvent() which again calls updateGL() and so on...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Mostafa WasatM 1 Reply Last reply
      0
      • jsulmJ jsulm

        I guess updateGL() call causes paintEvent() which again calls updateGL() and so on...

        Mostafa WasatM Offline
        Mostafa WasatM Offline
        Mostafa Wasat
        wrote on last edited by
        #3

        @jsulm There're no calls to paintEvent() or update() inside updateGL()

        void OpenGLWidget::updateGL()
        {
            makeCurrent();
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glEnable(GL_DEPTH_TEST);
            glDepthFunc(GL_LEQUAL);  //LEQUAL
        
            glEnable(GL_CULL_FACE);
            glFrontFace(GL_CW);
            glLineWidth(1.0f);
        
           // glDisable(GL_DITHER);
            glEnable(GL_LINE_SMOOTH);
            glEnable(GL_MULTISAMPLE);
            glViewport(0,0,m_width , m_height);
        
            m_camera = m_cameraController.toMatrix();
        
            QVector3D lightDirection;
            switch (m_currView) {
                case TopView:
                    lightDirection = QVector3D(0.0,0.0,1.0);
                    break;
                case BottomView:
                    lightDirection = QVector3D(0.0,0.0,-1.0);
                    break;
                case LeftView:
                    lightDirection = QVector3D(-1.0,0.0,0.0);
                    break;
                case RightView:
                    lightDirection = QVector3D(1.0,0.0,0.0);
                    break;
                case FrontView:
                    lightDirection = QVector3D(0.0,-1.0,0.0);
                    break;
                case BackView:
                    lightDirection = QVector3D(0.0,1.0,0.0);
                    break;
            }
            lightDirection.normalize();
            QVector3D directionalColor = QVector3D(0.3,0.3,0.3);
            QVector3D ambientLight = QVector3D(0.5,0.5,0.5);
        
            m_world.setToIdentity();
            m_world.translate(m_modelBox.getCenterPoint());
            m_world.rotate(m_rotation);
            m_world.scale(1.0f, 1.0f, m_worldZScalar);
            m_world.translate(-m_modelBox.getCenterPoint());
            QMatrix3x3 normalMatrix = m_world.normalMatrix();
        
            if(geometries){
                if(!m_drawWireFrame){
                    m_programGrid->bind();
                    //Set MVP Uniforms
                    m_programGrid->setUniformValue(m_projMatrixLoc, m_proj);
                    m_programGrid->setUniformValue(m_mvMatrixLoc, m_camera * m_world);
                    m_programGrid->setUniformValue(m_normalMatrixLoc, normalMatrix);
        
                    //Set Lighting Uniforms.
                    m_programGrid->setUniformValue(m_lightDirectionLoc, lightDirection);
                    m_programGrid->setUniformValue(m_directionalColorLoc, directionalColor);
                    m_programGrid->setUniformValue(m_ambientColorLoc, ambientLight);
        
                    //Draw Grid Geometry
                    geometries->drawGeometry(m_programGrid);
                    m_programGrid->release();
        
                    //Draw Border Lines
                    if(m_showBorders){
                        m_programLines->bind();
                        m_programLines->setUniformValue(m_projMatrixLocLines, m_proj);
                        m_programLines->setUniformValue(m_mvMatrixLocLines, m_camera * m_world);
                        geometries->drawLines(m_programLines, QVector3D(0.0,0.0,0.0));
                        m_programLines->release();
                    }
                }else{
                    m_programLines->bind();
                    m_programLines->setUniformValue(m_projMatrixLocLines, m_proj);
                    m_programLines->setUniformValue(m_mvMatrixLocLines, m_camera * m_world);
                    geometries->drawLines(m_programLines, QVector3D(1.0,1.0,1.0));
                    m_programLines->release();
                }
            }
        
            if(wellgeometries){
                glLineWidth(4.0f);
                m_programLines->bind();
                m_programLines->setUniformValue(m_projMatrixLocLines, m_proj);
                m_programLines->setUniformValue(m_mvMatrixLocLines, m_camera * m_world);
                wellgeometries->drawLines(m_programLines, QVector3D(1.0,0.0,0.0));
                m_programLines->release();
            }
        
            if(m_showCompass){
                glDisable(GL_DEPTH_TEST);
                glViewport(0,0,100,100);
        
                m_world.setToIdentity();
                m_world.translate(0,0,-5);
                m_world.rotate(m_cameraController.rotation().inverted());
                m_world.rotate(m_rotation);
        
                QMatrix4x4 proj;
                // Set near plane, far plane , field of view
                const qreal zNear = 1.0f, zFar = 150.0f, fov = 45.0;
                proj.setToIdentity();
                proj.perspective(fov, 1.0f, zNear, zFar);
        
                m_programGrid->bind();
                m_programGrid->setUniformValue(m_projMatrixLoc, proj);
                m_programGrid->setUniformValue(m_mvMatrixLoc, m_world);
                m_programGrid->setUniformValue(m_normalMatrixLoc, normalMatrix);
        
                //Set Lighting Uniforms.
                m_programGrid->setUniformValue(m_lightDirectionLoc, lightDirection);
                m_programGrid->setUniformValue(m_directionalColorLoc, directionalColor);
                m_programGrid->setUniformValue(m_ambientColorLoc, ambientLight);
                compass->drawCompassGeometry(m_programGrid);
                m_programGrid->release();
            }
        
            //doneCurrent();
        }
        
        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