Hi, this is a "spin-off" question of the thread here.

To keep control over available screen space I want to know the visible part of a QGraphicsScene - in scene coordinates.

To verify that my information is correct, I want to draw a black rectangle all over the visble scene area. Of course, the rectangle is just for testing purposes :-)

I've tried the following approach:
Qt Code:
  1. MainWindow::MainWindow()
  2. {
  3.  
  4. this->showMaximized();
  5.  
  6. scene=new QGraphicScene(this);
  7. view = new QGraphicsView(scene);
  8. QWidget *widget = new QWidget;
  9. QHBoxLayout *layout = new QHBoxLayout;
  10.  
  11.  
  12. //widget->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  13. setCentralWidget(widget);
  14. widget->setLayout(layout);
  15. layout->addWidget(view);
  16.  
  17. this->scene->setSceneRect(this->view->rect());
  18.  
  19. rectItem->setRect(this->view->mapToScene(this->view->rect()).boundingRect());
  20.  
  21. scene->addItem(rectItem);
  22. rectItem->setZValue(1000);
  23. rectItem->setBrush(QBrush(Qt::black,Qt::SolidPattern));
  24.  
  25.  
  26. view->setRenderHints(QPainter::HighQualityAntialiasing|QPainter::TextAntialiasing);
  27. view->setDragMode(QGraphicsView::ScrollHandDrag);
  28. view->setInteractive(true);
  29. view->setMouseTracking(true);
  30.  
  31.  
  32.  
  33. [...put other stuff onto scene...]
  34.  
  35. }
To copy to clipboard, switch view to plain text mode 

I'd love to see a black screen now - but the RectItem is much smaller than expected - thus I have quite obviously made a mistake in getting the size of the viewable area...

Only the code seems logical and correct to me.

Desired result: desiredResult.jpg

Actual result: viewportRecNewTry.jpg

What am I doing wrong?