Results 1 to 2 of 2

Thread: Scene Coordinates

  1. #1
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Re: Scene Coordinates

    I’m attempting to get a better handle on the Qt coordinate system by creating a scene that is 600 by 600 with the top left corner having an x value of -300 and a y value of 300. Whereas the bottom right corner x value would be 300 and the y value would be -300. The reason for doing this, is to have the center point x and y values be 0,0.
    Qt Code:
    1. qreal xTL(-300);
    2. qreal yTL(300);
    3. QSizeF rectSize(600, 600);
    4. QPointF sceneTopLeft(xTL, yTL);
    5. QRectF sceneRect(sceneTopLeft, rectSize);
    6.  
    7. pScene = new QGraphicsScene();
    8. pScene->setSceneRect(sceneRect);
    9. ui->graphicsView->setScene(pScene);
    10.  
    11. QPointF rectMiddle = sceneRect.center();
    12. QPointF rectTopLeft = sceneRect.topLeft();
    13. QPointF rectBotRight = sceneRect.bottomRight();
    14.  
    15. qreal rectWidth = sceneRect.width();
    16. qreal rectHeight = sceneRect.height();
    To copy to clipboard, switch view to plain text mode 
    When de-bugging I see the following values. I would expect the Y values for rectMiddle and rectBotRight to be 0 and -300 respectivly, yet they are double that!

    Debug ouput...
    Qt Code:
    1. [FONT=Courier New]Locals
    2. parent 0x0 QWidget*
    3. rectBotRight (300.0, 900.0) QPointF
    4. rectHeight 600.0 qreal
    5. rectMiddle (0.0, 600.0) QPointF
    6. rectSize (600.0, 600.0) QSizeF
    7. rectTopLeft (-300.0, 300.0) QPointF
    8. rectWidth 600.0 qreal
    9. sceneRect 600.0x600.0-300.0+300.0 QRectF
    10. sceneTopLeft (-300.0, 300.0) QPointF
    11. this @0x28fcbc MainWindow
    12. xTL -300.0 qreal
    13. yTL 300.0 qreal[/FONT]
    To copy to clipboard, switch view to plain text mode 

    So, what am I missing? Can anyone provide an explanation of this?

    Thanks in advance.

    I’m attempting to get a better handle on the Qt coordinate system by creating a scene that is 600 by 600 with the top left corner having an x value of -300 and a y value of 300. Whereas the bottom right corner x value would be 300 and the y value would be -300. The reason for doing this, is to have the center point x and y values be 0,0.
    Qt Code:
    1. qreal xTL(-300);
    2. qreal yTL(300);
    3. QSizeF rectSize(600, 600);
    4. QPointF sceneTopLeft(xTL, yTL);
    5. QRectF sceneRect(sceneTopLeft, rectSize);
    6.  
    7. pScene = new QGraphicsScene();
    8. pScene->setSceneRect(sceneRect);
    9. ui->graphicsView->setScene(pScene);
    10.  
    11. QPointF rectMiddle = sceneRect.center();
    12. QPointF rectTopLeft = sceneRect.topLeft();
    13. QPointF rectBotRight = sceneRect.bottomRight();
    14.  
    15. qreal rectWidth = sceneRect.width();
    16. qreal rectHeight = sceneRect.height();
    To copy to clipboard, switch view to plain text mode 
    When de-bugging I see the following values. I would expect the Y values for rectMiddle and rectBotRight to be 0 and -300 respectivly, yet they are double that!

    Debug ouput...
    Qt Code:
    1. [FONT=Courier New]Locals
    2. parent 0x0 QWidget*
    3. rectBotRight (300.0, 900.0) QPointF
    4. rectHeight 600.0 qreal
    5. rectMiddle (0.0, 600.0) QPointF
    6. rectSize (600.0, 600.0) QSizeF
    7. rectTopLeft (-300.0, 300.0) QPointF
    8. rectWidth 600.0 qreal
    9. sceneRect 600.0x600.0-300.0+300.0 QRectF
    10. sceneTopLeft (-300.0, 300.0) QPointF
    11. this @0x28fcbc MainWindow
    12. xTL -300.0 qreal
    13. yTL 300.0 qreal[/FONT]
    To copy to clipboard, switch view to plain text mode 

    So, what am I missing? Can anyone provide an explanation of this?

    Thanks in advance.


    Added after 14 minutes:


    I guess I'm pretty obtuse when it comes to Qt's Y scale decreasing in the down direction, but I think that was my problem. Needed the top left corner to be -300, -300 not 300, -300.

    Hopefully someone else may find this helpful.
    Last edited by Corny; 25th July 2017 at 00:18.

  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: Scene Coordinates

    I’m attempting to get a better handle on the Qt coordinate system by creating a scene that is 600 by 600 with the top left corner having an x value of -300 and a y value of 300. Whereas the bottom right corner x value would be 300 and the y value would be -300. The reason for doing this, is to have the center point x and y values be 0,0.
    Needed the top left corner to be -300, -300 not 300, -300.
    Well, these two statements are in conflict. You can't have a bottom right corner where the y coordinate is -300 if the y coordinate of the top left corner is also -300. This gives a width of 0.

    I presume you meant that the top left should be (-300, -300) and bottom right (300, 300). This puts the center at (0,0). But you could also have had the same center if top left was (-300, 300) and bottom right was (300, -300). You couldn't use the constructor that you did (QPointF, QSizeF), because this assumes positive-going coordinates in screen orientation (positive y is down). However, the QRectF constructor that takes two QPointF arguments would let you invert the rectangle so positive y is up, like it is in a geometrical coordinate system.

    Remember that the coordinate system for QGraphicsScene is independent of the views and can be in any coordinate scale you want. It is the mapping to the QGraphicsView that determines how it appears on screen.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 10th April 2013, 09:08
  2. Calculate scene coordinates from QGraphicsLinearLayout
    By onurozcelik in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2011, 08:38
  3. QGraphicsView, QGraphicsScene item coordinates in scene
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2010, 10:02
  4. Problem with QGraphicsView/Scene coordinates
    By Andrewshkovskii in forum Newbie
    Replies: 12
    Last Post: 19th October 2009, 10:41
  5. Viewport and scene coordinates
    By aurelius in forum Newbie
    Replies: 2
    Last Post: 30th October 2008, 23:47

Tags for this Thread

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.