PDA

View Full Version : How to set QGraphicsScene to a specific coordinate system



qlands
3rd May 2012, 16:25
Hi,

I want to draw polygons in a QGraphicsScene but where the polygons has latitude/longitude positions. In a equirectangular projection the coordinates goes from:



^
90
|
|
-180----------------------------------->180
|
|
-90


How can I set the QGraphicsScene to such projection?

Many thanks,
Carlos.

d_stranz
4th May 2012, 17:17
QGraphicsScene::setSceneRect() won't do it for you?

amleto
5th May 2012, 13:01
you should take note that the scene will grow if you try to place anything outside of the current scene bounds. You may like to consider specialising QGraphicsScene to adjust this behaviour.

qlands
7th May 2012, 16:26
Hi,

I used m_scene->setSceneRect(-180, -90, 360, 180) in union with graphicsView->scale(1, -1); and the coordinate system is fine. However if I maximize the windows the qGraphisView covers almost all screen and the coordinates at the extreme of the graphicsView are outside -180 <----> 180 horizontally and outside -90 <------> 90 vertically. How can I make the QGraphicsScene or the qGraphisView to always keep the extremes in -180 to 180 and 90 to -90? Something like if I maximize the windows not increase the boundaries but zoom into the boundaries.

Thanks for your help.

amleto
7th May 2012, 16:38
you would have to hook into resize event and set a zoom transform so that the bounds of the view match the bounds of the scene.

qlands
7th May 2012, 16:53
Right... I can work in the resize event but


set a zoom transform so that the bounds of the view match the bounds of the scene

How I do that?

wysota
7th May 2012, 17:24
Hi,

I used m_scene->setSceneRect(-180, -90, 360, 180) in union with graphicsView->scale(1, -1); and the coordinate system is fine. However if I maximize the windows the qGraphisView covers almost all screen and the coordinates at the extreme of the graphicsView are outside -180 <----> 180 horizontally and outside -90 <------> 90 vertically. How can I make the QGraphicsScene or the qGraphisView to always keep the extremes in -180 to 180 and 90 to -90? Something like if I maximize the windows not increase the boundaries but zoom into the boundaries.

Thanks for your help.

Reimplement resizeEvent for the view and call QGraphicsView::fitInView() passing the rect you want matched in the view.

d_stranz
7th May 2012, 21:58
Reimplement resizeEvent for the view and call QGraphicsView::fitInView() passing the rect you want matched in the view.

This works just fine, but then you run into the problem that if you use the default, the aspect ratio changes, the font scaling gets strange, and the plot just gets ugly. I had to jump through a lot of hoops to get an x-y plot look "normal" no matter what size window it was in. Using Qt::KeepAspectRatio makes it a bit better, but then you must reposition the scene by using QGraphicsView::centerOn().

wysota
8th May 2012, 00:51
This works just fine, but then you run into the problem that if you use the default, the aspect ratio changes, the font scaling gets strange, and the plot just gets ugly.
Nobody said anyone was to use any defaults. There are three values to pass for the argument to fitInView and trying all of them is not that hard. The method does exactly what it name says -- it makes sure a specific rectangle matches the view. it says nothing about what the view gets centred on.