PDA

View Full Version : How to use QGraphicsView in designer



dpatel
6th June 2011, 09:55
Hi,

I have created a user interface by code (not using designer). I created a custom QGraphicsView and add all widgets to it, did override mousewheel event to support zoom in and zoom out. But now I have to do the same thing using designer.
So I drop a QGraphicsView in Mainwindow and promote it to my custom class. Then I drop couple of push buttons on it and try to run. The scaling doesn't work now. The other change I have now is am passing a QWidget as argument to QGraphicsView constructor instead of QGraphicsScene. Is that the reason that scaling stopped working?

Also how can I add widgets to QGraphicsView (using designer) so that I can scale them?

Thanks.

wysota
6th June 2011, 10:48
Also how can I add widgets to QGraphicsView (using designer) so that I can scale them?
The view displays (and scales) the contents of the scene. Dropping widgets on a graphics view in Designer doesn't add them to the scene. Designer can't populate the scene for you, you need to do it in code.

dpatel
6th June 2011, 11:15
Thanks wysota for the information.

After seeing your reply I tried following code but I don't see any widgets that I placed on the MainWindow, only the graphics view with white background which covers all main windows is shown.



QGraphicsScene *pScene=new QGraphicsScene;
m_pGraphicsView=new QGraphicsView(pScene);
pScene->addWidget(this->centralWidget());

//ui.d->setVisible(false);
setCentralWidget(m_pGraphicsView);



I have added the code in QMainWindow's constructor just after ui.setup(this) call. Can you please tell me why its not working. Is there any way I can do it?

D.

wysota
6th June 2011, 11:51
Try analyzing the code you have written, it doesn't make sense. It's like you had a yellow box and a red box and you put the red box in the yellow box and then you'd like to place that yellow box (containing the red box) in the red box.