Qt 4.8。在QPixmap地理地图上绘制弧度坐标对象

时间:2016-03-02 15:39:23

标签: qt qgraphicsview qgraphicsscene coordinate-transformation qt4.8

我试图在QPixmap地理地图上绘制带有弧度坐标的对象。

QRectF zone( QPointF( 0.86459    , 1.8675)
           , QPointF( 0.86459+0.1, 1.8675+0.1));

QGraphicsScene gs;
gs.setParent( w.graphicsView()); //it's my QGraphicsView widget
gs.setSceneRect( zone);
w.graphicsView()->setScene( gs);

QGraphicsItem * gpi

  = gs.addPixmap( QPixmap::fromImage( QImage( "map.jpg"))); //For test reasons it's an red square (200x200)

//Let's paint a green line from bottom-left to top-right:
gs.addLine( 0.86459    , 1.8675
          , 0.86459+0.1, 1.8675+0.1, QPen( Qt::green));

w.graphicsView()->scale( 2000
                       , 2000); //as we want zone to correspond 200x200 square
w.graphicsView()->rotate( -90); //as geo coords are rotated

w.graphicsView()->setScene( &gs);

/*1*///    gpi->setFlag( QGraphicsItem::ItemIgnoresTransformations);

gpi->setTransform( QTransform::fromScale( 1/2000
                                        , 1/2000)); //makes QPixmap size 0.1x0.1

gpi->setTransform( QTransform::fromTranslate( 0.86459
                                            , 1.8675), true);

麻烦的是我显示的是绿线,而不是地图红色方块。如果相对于接下来的两行取消注释line / 1 /,我也只得到绿线。

0 个答案:

没有答案