Results 1 to 9 of 9

Thread: How to set QGraphicsScene to a specific coordinate system

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How to set QGraphicsScene to a specific coordinate system

    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:

    Qt Code:
    1. ^
    2. 90
    3. |
    4. |
    5. -180----------------------------------->180
    6. |
    7. |
    8. -90
    To copy to clipboard, switch view to plain text mode 

    How can I set the QGraphicsScene to such projection?

    Many thanks,
    Carlos.
    Last edited by qlands; 3rd May 2012 at 15:32.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    QGraphicsScene::setSceneRect() won't do it for you?

  3. #3
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. #4
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    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.

  5. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #6
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    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?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QGraphicsScene to a specific coordinate system

    Quote Originally Posted by qlands View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to set QGraphicsScene to a specific coordinate system

    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().

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to set QGraphicsScene to a specific coordinate system

    Quote Originally Posted by d_stranz View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QGraphicsScene Coordinate System
    By grayfox in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2016, 20:34
  2. qt coordinate system
    By qtlearner123 in forum Newbie
    Replies: 1
    Last Post: 17th April 2012, 15:20
  3. QGraphicsView coordinate system
    By edxxgardo in forum Qt Programming
    Replies: 3
    Last Post: 12th July 2011, 14:38
  4. coordinate system
    By Wojtek.wk in forum Newbie
    Replies: 7
    Last Post: 12th April 2010, 13:47
  5. The coordinate system
    By avis_phoenix in forum Qt Programming
    Replies: 1
    Last Post: 28th July 2008, 12:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.