Reputation: 2246
I am writing a scene editor to edit levels for an iphone game. The point of origin within the iphone/ipad environment is the bottom left of the display.
How can I correctly move the origin within the QGraphicsScene object ? I have tried with
// iWidth and iHeight are maximum scene dimension values
pScene->setSceneRect(0, iHeight, iWidth, iHeight);
but this doesn't work.
Without going to a complicated (at least for me) transformation matrix, how should I be moving the origin point ?
EDIT :
As requested, here is a resume of how I am creating the scene and adding images to it :
// Creation of the Scene within a QMainWindow derived class
QGraphicsScene* m_pScene = new QGraphicsScene(this);
ui->levelScene->setScene(m_pScene);
// insertion of the background png image
QPixmap* pm = new QPixmap(strFileName, 0);
QGraphicsPixmapItem* pi = new QGraphicsPixmapItem();
pi->setPixmap(*pm);
m_pScene->addItem(pi);
// adjustment of the layout
m_pScene->setSceneRect(0, iHeight, iWidth, iHeight);
// add a movable png image to the scene above the background
pm = new QPixmap(*g_pChoData->m_pcDirImages + "/" + pChoElem->m_Image, 0);
pi = new QGraphicsPixmapItem();
pi->setPixmap(*pm);
pi->setPos(iPosX, iPosY);
pi->setZValue(iPosZ);
pi->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
m_pScene->addItem(pi);
Upvotes: 2
Views: 3482
Reputation: 2246
Here is the solution, at least in my case.
To put 0,0 at the bottom left -
m_pScene->setSceneRect(0, -iHeight, iWidth, iHeight);
Then, all images inserted into the scene need to have their Y position adjusted :
pi->setPos(iPosX, -iPosY);
Last little trick which caused me problems was that the clients reference point for an image is the center of the image and not a corner.
Thank you to all who helped here.
Upvotes: 1