tags:

views:

550

answers:

3

Hi!

I would like to create a simple thumbnail viewer using QGLWidget, QGraphicsScene and QGraphicsView. And I have a problem with placing QGLWidget on QGraphicsScene. The code is similar to this:

QGraphicsScene *testScene = new QGraphicsScene (0, 0, 400, 400, 0);

QGLWidget *testWidget1 = new QGLWidget();
testWidget1->renderText("Test text1");

QGLWidget *testWidget2 = new QGLWidget();
testWidget2->renderText("Test text2");

testScene->addWidget(testWidget1);
testScene->addWidget(testWidget2);

QGraphicsView *testView = new QGraphicsView();
testView->setScene(testScene);
testView->show()

It is possible to place few QGLWidgets on QGraphicsScene/QGraphicsView? Where I doing something wrong? Is there any other component on which I could embed QGLWidgets and show them on the screen?

Thanks for help

A: 

From the QGraphicsView docs:

To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget.

So, in order to draw text on the view, use a QGraphicsTextItem rather than trying to draw text using the QGLWidget.

Kaleb Pederson
+1  A: 

The QGraphicsScene::addWidget documentation states that QGLWidget is not a supported widget type.

Parenting a QGLWidget onto the viewport of the QGraphicsView doesn't seem to work either.

Edit:

Actually parenting a QGLWidget to the viewport does work provided I put the renderText call within the paintGL method of my test GL widget.

Troubadour
A: 

Setting the parent of a QGLWidget to the QGraphicsView's viewport() worked. However, I want to paint the QGLWidget as the background and then have a QGraphicsScene render in the foreground of the QGraphicsView.

I don't know much Qt, and I'd appreciate any inputs on how to achieve this.

Thanks.

Akarsh Simha