QT QGraphicsScene将原点设置为左下角
QT QGraphicsScene set origin to bottom left
我正在编写一个场景编辑器来编辑iPhone游戏的关卡。iPhone/ipad环境中的原点是显示屏的左下角。
如何在 QGraphicsScene 对象中正确移动原点?我试过
// iWidth and iHeight are maximum scene dimension values
pScene->setSceneRect(0, iHeight, iWidth, iHeight);
但这行不通。
在不去一个复杂的(至少对我来说)变换矩阵的情况下,我应该如何移动原点?
编辑:
根据要求,以下是我如何创建场景并向其添加图像的简历:
// 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);
这是解决方案,至少就我而言。
将 0,0 放在左下角 -
m_pScene->setSceneRect(0, -iHeight, iWidth, iHeight);
然后,插入到场景中的所有图像都需要调整其Y位置:
pi->setPos(iPosX, -iPosY);
给我带来问题的最后一个小技巧是图像的客户端参考点是图像的中心而不是角落。
感谢所有在这里提供帮助的人。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 如何在boost beast http请求中设置http头
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 如何在24位SDL_Surface上设置像素的颜色
- std::设置自定义比较器
- 如何设置一个范围来提取我想要获得的信息
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- 通过选项卡的文本设置QTabWidget顺序
- QT QGraphicsScene将原点设置为左下角
- 如何在 3D 中设置左下角的原点