开发者

Using QGraphicsView to display a local map

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 - s开发者_运维技巧imply 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.


  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! :)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜