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. [SOLVED] How to force QGLWidget to update screen?
Qt 6.11 is out! See what's new in the release blog

[SOLVED] How to force QGLWidget to update screen?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I'm drawing a simple scene with Open GL. I've subclassed QGLWidget and overriden paintGL(). Nothing fancy there:

    @void CGLWidget::paintGL()
    {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    gluLookAt (120.0, 160.0, -300.0, 0.0 + 120.0, 0.0 + 160.0, 2.0 - 300.0, 0.0, 1.0, 0.0);
    glScalef(1.0f/300.0f, 1.0f/300.0f, 1.0f/300.0f);
    glClear(GL_DEPTH_BUFFER_BIT);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(80.0, width()/(double)height(), 5.0, 100000.0);
    glMatrixMode(GL_MODELVIEW);
    
    glBegin(GL_POINTS);
    glColor3f(1.0f,0.6f,0.0f);
    glVertex3d(x, y, z);
    // ...drawing some more points...
    glEnd();
    

    }@

    I have a timer in main window which triggers updateGL() of GL widget. I've verified that it results in paintGL() being called. However, the actual picture on the screen is only updated very rarely. Even if I resize the window, scene is not updated. Why is that and how can I force it to update?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Violet Giraffe
      wrote on last edited by
      #2

      Found the problem, sorry for bothering. Was just a logical mistake, unrelated to GLWidget or the code in the OP.

      Found out I should call update() and not updateGL(), though.

      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