I´ve been reading about QGraphicsView/Scene/Item all day and still I fail to understand how it works. I started with QT Creator and added a QGraphicsView to the mainWindow. Then I subclassed QGraphicsScene and QGraphicsItem(I probably need to subclass the QGraphicsView later on). I use shapelib to open a shape-file and If I´ve done it right it will be implemented as a QGraphicsItem. I add the item to the scene and the scene to the view. I can see the map(shapefile) but it´s centered and very small. So I thought let´s change the coordinatesystem of the scene... And this is where I got stuck.
I know the boundaries of the GraphicsView and the Scene. I also know the boundaries of the shapefile. Why can´t I tell the scene to have the same boundaries as the shapefile but extend it to the size of the view!?
Maybe it isn´t hard but obviously I don´t have the brains for it so any help at all will be very appreciated.

Code for subclassed QGraphicsItem

Qt Code:
  1. item::item(QGraphicsItem *parent)
  2. : QGraphicsItem(parent)
  3. {
  4. }
  5.  
  6. QRectF item::boundingRect() const
  7. {
  8. QRectF recWindow;
  9. recWindow.setBottomLeft(QPointF(sBoundingBox.minX,sBoundingBox.minY));
  10. recWindow.setBottomRight(QPointF(sBoundingBox.maxX, sBoundingBox.minY));
  11. recWindow.setTopLeft(QPointF(sBoundingBox.minX,sBoundingBox.maxY));
  12. recWindow.setTopRight(QPointF(sBoundingBox.maxX,sBoundingBox.maxY));
  13. return recWindow;
  14. }
  15.  
  16. void item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  17. {
  18. OpenShapeFile("./Maps/Norden_wgs84.shp");
  19. painter->setRenderHint(QPainter::Antialiasing);
  20. painter->setBrush(Qt::blue);
  21.  
  22. for(int i = 0;i< vMap.size(); i++)
  23. {
  24. painter->drawPolyline(vMap.at(i)->p.data() ,vMap.at(i)->p.size());
  25. }
  26. }
To copy to clipboard, switch view to plain text mode 

I´m not really doing anything in the subclassed QGraphicsScene yet so I don´t think there is any reason to show the code.

And here is the mainWindow
Qt Code:
  1. IceChart3::IceChart3(QWidget *parent)
  2. : QMainWindow(parent)
  3. {
  4. ui.setupUi(this);
  5.  
  6. QRect sceneRect;
  7. sceneRect.setBottomLeft(QPoint(4,52));
  8. sceneRect.setBottomRight(QPoint(42, 52));
  9. sceneRect.setTopLeft(QPoint(4,72));
  10. sceneRect.setTopRight(QPoint(42,72));
  11.  
  12. scene = new MyScene(this);
  13. scene->setSceneRect(sceneRect);
  14.  
  15. itemMap = new item();
  16.  
  17. scene->addItem(itemMap);
  18.  
  19. //Flip upside down.
  20. ui.graphicsView->scale(1,-1);
  21.  
  22. //Set scene to view
  23. ui.graphicsView->setScene(scene);
To copy to clipboard, switch view to plain text mode