PDA

View Full Version : Putting a QGraphicsScene into QMdiSubWindow



steg90
2nd October 2007, 09:26
Hi,

I have a MDI application. I have created a QGraphicsScene / QGraphicsView. I was wondering how I could put this into my QMdiSubWindow. I did do the following, but this doesn't seem correct as the scenes background isn't blue and the paint event is not being called on the graphics item?



CanScene canScene;
QGraphicsView view(&canScene);

QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( &view );
subWindow->setWindowIcon(QIcon(QString::fromUtf8(":/QTCanMonitor/Resources/Winamp.png")));
subWindow->setMinimumSize( 200, 200 );

canScene.setBackgroundBrush(Qt::blue);
view.resize(500,500);
view.scale(0.95,0.95);
view.show();



Regards,
Steve

marcel
2nd October 2007, 09:48
Create the scene on the heap. In your code, the scene gets deleted as soon as the function exists.

steg90
2nd October 2007, 09:53
Thanks.

Ok, tried that, this is what I now have :



CanScene* pcanScene = new CanScene(this);
pcanScene->setSceneRect( QRectF( 0, 0, 5000, 5000 ) );
pcanScene->setBackgroundBrush(Qt::blue);
QGraphicsView view(pcanScene);

QMdiSubWindow* subWindow = m_pworkspace->addSubWindow( &view );



Still not blue background and paint event not being called?

Regards,
Steve

steg90
2nd October 2007, 09:55
Ok, it was a problem with not creating the graphics view on the heap also ;)

Marcel - many thanks for taking time to help, it is appreciated.

Regards,
Steve