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.setItemIndexMethod(QGraphicsScene::NoIndex);
scene.addWidget(new BackGroundGLWidget());QGraphicsView view(&scene); view.setMaximumSize(800, 600); view.setAlignment(Qt::AlignCenter); 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! QFontMetrics metrics(font); QString bottomRightText("I am always at the bottom right."); renderText((width() - metrics.width(bottomRightText) - 10)/2, (height() - metrics.height() + 10)/2, bottomRightText, font);
@
-
So, how would I set a jpg image as overlay dialogs, buttons, lines and the like?
Laurence -
-
[quote author="cazador7907" date="1296309277"]
So, how would I set a jpg image as overlay dialogs, buttons, lines and the like?Laurence -
[/quote]
I'm not getting it... do you have all of that in a QGraphicsScene or as ordinary widgets? Where and how is OpenGL involved in this?