Corny
25th July 2017, 01:19
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.
qreal xTL(-300);
qreal yTL(300);
QSizeF rectSize(600, 600);
QPointF sceneTopLeft(xTL, yTL);
QRectF sceneRect(sceneTopLeft, rectSize);
pScene = new QGraphicsScene();
pScene->setSceneRect(sceneRect);
ui->graphicsView->setScene(pScene);
QPointF rectMiddle = sceneRect.center();
QPointF rectTopLeft = sceneRect.topLeft();
QPointF rectBotRight = sceneRect.bottomRight();
qreal rectWidth = sceneRect.width();
qreal rectHeight = sceneRect.height();
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...
Locals
parent 0x0 QWidget*
rectBotRight (300.0, 900.0) QPointF
rectHeight 600.0 qreal
rectMiddle (0.0, 600.0) QPointF
rectSize (600.0, 600.0) QSizeF
rectTopLeft (-300.0, 300.0) QPointF
rectWidth 600.0 qreal
sceneRect 600.0x600.0-300.0+300.0 QRectF
sceneTopLeft (-300.0, 300.0) QPointF
this @0x28fcbc MainWindow
xTL -300.0 qreal
yTL 300.0 qreal
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.
qreal xTL(-300);
qreal yTL(300);
QSizeF rectSize(600, 600);
QPointF sceneTopLeft(xTL, yTL);
QRectF sceneRect(sceneTopLeft, rectSize);
pScene = new QGraphicsScene();
pScene->setSceneRect(sceneRect);
ui->graphicsView->setScene(pScene);
QPointF rectMiddle = sceneRect.center();
QPointF rectTopLeft = sceneRect.topLeft();
QPointF rectBotRight = sceneRect.bottomRight();
qreal rectWidth = sceneRect.width();
qreal rectHeight = sceneRect.height();
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...
Locals
parent 0x0 QWidget*
rectBotRight (300.0, 900.0) QPointF
rectHeight 600.0 qreal
rectMiddle (0.0, 600.0) QPointF
rectSize (600.0, 600.0) QSizeF
rectTopLeft (-300.0, 300.0) QPointF
rectWidth 600.0 qreal
sceneRect 600.0x600.0-300.0+300.0 QRectF
sceneTopLeft (-300.0, 300.0) QPointF
this @0x28fcbc MainWindow
xTL -300.0 qreal
yTL 300.0 qreal
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 :confused: 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.
qreal xTL(-300);
qreal yTL(300);
QSizeF rectSize(600, 600);
QPointF sceneTopLeft(xTL, yTL);
QRectF sceneRect(sceneTopLeft, rectSize);
pScene = new QGraphicsScene();
pScene->setSceneRect(sceneRect);
ui->graphicsView->setScene(pScene);
QPointF rectMiddle = sceneRect.center();
QPointF rectTopLeft = sceneRect.topLeft();
QPointF rectBotRight = sceneRect.bottomRight();
qreal rectWidth = sceneRect.width();
qreal rectHeight = sceneRect.height();
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...
Locals
parent 0x0 QWidget*
rectBotRight (300.0, 900.0) QPointF
rectHeight 600.0 qreal
rectMiddle (0.0, 600.0) QPointF
rectSize (600.0, 600.0) QSizeF
rectTopLeft (-300.0, 300.0) QPointF
rectWidth 600.0 qreal
sceneRect 600.0x600.0-300.0+300.0 QRectF
sceneTopLeft (-300.0, 300.0) QPointF
this @0x28fcbc MainWindow
xTL -300.0 qreal
yTL 300.0 qreal
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.
qreal xTL(-300);
qreal yTL(300);
QSizeF rectSize(600, 600);
QPointF sceneTopLeft(xTL, yTL);
QRectF sceneRect(sceneTopLeft, rectSize);
pScene = new QGraphicsScene();
pScene->setSceneRect(sceneRect);
ui->graphicsView->setScene(pScene);
QPointF rectMiddle = sceneRect.center();
QPointF rectTopLeft = sceneRect.topLeft();
QPointF rectBotRight = sceneRect.bottomRight();
qreal rectWidth = sceneRect.width();
qreal rectHeight = sceneRect.height();
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...
Locals
parent 0x0 QWidget*
rectBotRight (300.0, 900.0) QPointF
rectHeight 600.0 qreal
rectMiddle (0.0, 600.0) QPointF
rectSize (600.0, 600.0) QSizeF
rectTopLeft (-300.0, 300.0) QPointF
rectWidth 600.0 qreal
sceneRect 600.0x600.0-300.0+300.0 QRectF
sceneTopLeft (-300.0, 300.0) QPointF
this @0x28fcbc MainWindow
xTL -300.0 qreal
yTL 300.0 qreal
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 :confused: 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.