QGLWidget and QGraphicsScene Program Crash
I’ve been experimenting with rendering a QGLWidget within a QGraphicsScene. The program compiles just fine. However, when I attempt to render some text to the middle of the widget, the program will run for about a second and then it crashes. I’ve narrowed the problem down to the paintGL method (code below). However, I can’t figure out why it’s crashing.
//Main
- QGraphicsScene scene;
- scene.setSceneRect(0,0, 800, 600);
- scene.addWidget(new BackGroundGLWidget());
- view.setMaximumSize(800, 600);
- view.showMaximized();
- view.show();
PaintGL Code
- // Clear screen and depth buffer
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity(); // Reset view matrix
- glTranslatef(0.0f, 0.0f, -1.0f); // Move into screen 1 unit
- // Pulsing colors based on text position
- glColor3f(qMax(0.0, 1.0f * cos(cnt1)),
- qMax(0.0, 1.0 * sin(cnt2)),
- qMin(1.0, 1.0f - 0.5f * cos(cnt1 + cnt2)));
- // Print text on the screen
- QFont font;
- font.setBold(true);
- font.setPixelSize(18);
- // Print some text without taking the transformation into account
- // Very useful class to align some text in OpenGL at the absolute
- // borders of the screen!
- renderText((width() - metrics.width(bottomRightText) - 10)/2,
- (height() - metrics.height() + 10)/2, bottomRightText, font);
5 replies
You must log in to post a reply. Not a member yet? Register here!


