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:
- Add a map image to the scene and tell Qt how to map the actual image pixels to scene coordinates.
- 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.
- Put the pixmap into a QGraphicsPixmapItem and place it in the scene.
- 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.
- Update the pixmap and scale of the item as needed.
- Call fitInView() to zoom to the pixmap.
- Place other graphic items in the scene. Treat the units of the scene coordinate as meters.
- ...
- Profit! :)
精彩评论