Hi All,
Given the example code at:
http://doc.trolltech.com/qq/qq26-openglcanvas.zip
and a full write-up of what this code does:
http://doc.trolltech.com/qq/qq26-openglcanvas.html
i'm trying to modify the code such that I can embed an instance of OpenGLScene within one of the created dialogs, i.e. I want an embedded QGraphicsView within an QGraphicsScene.
If I make the following changes to the code, everything works fine:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGLWidget* tGLWidget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
GraphicsView view(tGLWidget);
view.setScene(new OpenGLScene(tGLWidget));
view.show();
view.resize(1024, 768);
return app.exec();
}
class GraphicsView : public QGraphicsView
{
public:
GraphicsView(QGLWidget* iGLWidget)
{
setWindowTitle(tr("3D Model Viewer"));
setViewport(iGLWidget);
setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
}
protected:
void resizeEvent(QResizeEvent *event) {
if (scene())
scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
QGraphicsView::resizeEvent(event);
}
};
OpenGLScene::OpenGLScene(QGLWidget* iGLWidget)
: m_wireframeEnabled(false)
, m_normalsEnabled(false)
, m_modelColor(153, 255, 0)
, m_backgroundColor(0, 170, 255)
, m_model(0)
, m_lastTime(0)
, m_distance(1.4f)
, m_angularMomentum(0, 40, 0)
{
QWidget *controls = createDialog(tr("Controls"));
if (iGLWidget) {
GraphicsView* tView = new GraphicsView(0);
tView->setScene(new OpenGLScene(0));
controls->layout()->addWidget(tView);
}
// ...
However, if I modify OpenGLScene's constructor as follows:
OpenGLScene::OpenGLScene(QGLWidget* iGLWidget)
: m_wireframeEnabled(false)
, m_normalsEnabled(false)
, m_modelColor(153, 255, 0)
, m_backgroundColor(0, 170, 255)
, m_model(0)
, m_lastTime(0)
, m_distance(1.4f)
, m_angularMomentum(0, 40, 0)
{
QWidget *controls = createDialog(tr("Controls"));
if (iGLWidget) {
GraphicsView* tView = new GraphicsView(iGLWidget); // change is here!
tView->setScene(new OpenGLScene(0));
controls->layout()->addWidget(tView);
}
// ...
i get a grey screen. In the snippet above, I'm now instructing all QGraphicsView objects to use a QGLWidget as the viewport. Furthermore, all QGraphicsView objects will use the _same_ QGLWidget.
What I'm trying to do is embed a widget that can draw OpenGL within a widget (such as a QDialog) which is in turn embedded within a QGraphicsScene that is using a QGraphicsView that is using QGLWidget as a viewport.
Any help would be greatly appreciated.
Bookmarks