Results 1 to 9 of 9

Thread: How to set QGraphicsScene to a specific coordinate system

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.


  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 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().

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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
  •  
Qt is a trademark of The Qt Company.