PDA

View Full Version : QGraphicsView coordinate system



edxxgardo
11th July 2011, 13:30
Hello everybody,

I am dealing with a simple application using a main window with menu bar and tool bar. After that, I set as main widget a QGraphicsView and inside it a QGraphicsScene. What I do is basically design inside QGraphicsScene and it works. But, my problem is that I don't get the size of the View and Scene.
1) I do
scene->setSceneRect(0,0,view->width(), view->height())
to set the scene as big as the view size, that in my case, because I used the showFullScreen() method in the main window, is 640x480. Doing so, I get the scene in the center of the window and the size is a quarter of the main window. Why the scene is not the full size of the view?

2) If I set, for example,
scene->setSceneRect(0,0,view->width()+200, view->height()+200)
then it is bigger as I would want.

My question is how can I do to get the scene the size of the View and why the view->width() does not work as parameter above. I would really appreciate any help, thx

mcosta
11th July 2011, 15:23
where you used


scene->setSceneRect(0,0,view->width(), view->height())
?

you should do in resizeEvent

d_stranz
11th July 2011, 20:32
Can also use QGraphicsView::fitInView() with Qt::KeepAspectRatio in the resize event if you don't want distortion due to changes in the width / height ratio on resizing. That also will center the scene in the view.

Note that calling setSceneRect() will change *all* views of the scene, not just the one with focus. So if you have the same scene displayed in more than one window, you want the method I described (which changes only the scaling used by the view, not the scene dimensions), otherwise the scene will look fine in one view, but not in any of the others.

edxxgardo
12th July 2011, 14:38
Thx a lot guys, I try it out and see if it works.