使用QGraphicsView显示本地地图

发布于 2024-10-05 23:22:05 字数 455 浏览 0 评论 0原文

我正在尝试使用 QGraphicsView 来显示地图图像并在其上绘制一些项目。地图边界采用笛卡尔坐标系,例如 NE(-500,200) 到 SW(600,-350)。我知道如何映射图像像素<-->我的坐标系。

我必须实现以下目标:

  1. 将地图图像添加到场景并告诉 Qt 如何将实际图像像素映射到场景坐标。
  2. 在其真实位置添加图形项目,例如 (-100,200)

执行 (2) 很简单 - 只需将项目添加到场景中即可。我如何实现(1)?调用 scene->addPixmap() 后该怎么办?

编辑 - 一些说明:

  • 我正在绘制几百米的室内区域
  • 地图将以两种方式实时变化:
    • 地图每隔几秒就会变大
    • 图形项目会移动、改变颜色等。

I'm trying to use QGraphicsView in order to display a map image and draw some items on top of it. The map boundaries are in a Cartesian coordinate system, for example NE(-500,200) to SW(600,-350). I know how to map image pixels <--> my coordinate system.

I would have to achieve the following:

  1. Add a map image to the scene and tell Qt how to map the actual image pixels to scene coordinates.
  2. Add graphic items at their real position, e.g. (-100,200)

Doing (2) is straightforward - simply add the item to the scene. How do I achieve (1)? what should I do after I call scene->addPixmap()?

Edit - A few clarifications:

  • I'm mapping an indoor area of a few hundred meters
  • The map will change at real-time in two ways:
    • The map gets bigger every few seconds
    • The graphic items move, change colors, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2024-10-12 23:22:05
  1. 将像素图放入 QGraphicsPixmapItem 并将其放置在场景中。
  2. 调用setScale()来映射QGraphicsPixmapItem,这样1米的地图到场景坐标中的 1 个单位。 IE。如果像素图中 10 个像素等于 1 米,则 setScale(0.1)。
  3. 根据需要更新项目的像素图和比例。
  4. 调用 fitInView() 缩放到像素图。
  5. 将其他图形项目放置在场景中。将场景坐标的单位视为米。
  6. ...
  7. 利润! :)
  1. Put the pixmap into a QGraphicsPixmapItem and place it in the scene.
  2. Call setScale() to map the QGraphicsPixmapItem so 1 meter maps to 1 unit in the scene coordinate. ie. setScale(0.1) if 10 pixels in the pixmap equal 1 meter.
  3. Update the pixmap and scale of the item as needed.
  4. Call fitInView() to zoom to the pixmap.
  5. Place other graphic items in the scene. Treat the units of the scene coordinate as meters.
  6. ...
  7. Profit! :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文