Hello!

I'd like to assign a QGraphicsScene to a QGraphicsView which is set as the central widget of the main window.

Moreover the scene coordinate system should be set as the view inner space...I wrote the following code:

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QGraphicsTextItem>
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6. QMainWindow(parent),
  7. ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10.  
  11. scene = new QGraphicsScene;
  12. view = new QGraphicsView;
  13. view->setScene(scene);
  14. view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  15. view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  16.  
  17. setCentralWidget(view);
  18.  
  19. scene->setSceneRect(view->geometry());
  20. view->setFocus();
  21.  
  22. showLine();
  23. }
  24.  
  25. void MainWindow::showLine()
  26. {
  27. scene->addLine(0, 0, 100, 100);
  28. }
  29.  
  30. MainWindow::~MainWindow()
  31. {
  32. delete ui;
  33. }
To copy to clipboard, switch view to plain text mode 

(scene and view are two MainWindow object's attributes)

but, running this code the line is drawn about at the center of the view...why doesn't the line start at the top left corner?

Thanks