Hi,

I have a problem about setting the rectangle size of the QGraphicsScene to QGraphicsView's visible part.

When I set the scene's rectangle using view's width and height, the scroll bars appear.

How can I determine the maximum visible size of the QGraphicsView so that I can set the scene's rectangle to maximum ?

The example code is below to demonstrate the problem:

Qt Code:
  1. #include <QApplication>
  2. #include <QtGui>
  3. #include <QDebug>
  4.  
  5. int main ( int argc, char *argv[] )
  6. {
  7. QApplication app ( argc, argv );
  8.  
  9. view.setGeometry ( 10, 10, 400, 300 );
  10. view.setScene ( new QGraphicsScene() );
  11.  
  12. qint32 gvWidth = view.width();
  13. qint32 gvHeight = view.height();
  14. view.setSceneRect ( -gvWidth / 2, -gvHeight / 2, gvWidth, gvHeight );
  15.  
  16. QGraphicsLineItem* line = new QGraphicsLineItem ( - gvWidth / 2, - gvHeight / 2, gvWidth / 2, gvHeight / 2 );
  17. view.scene()->addItem ( line );
  18.  
  19. view.show();
  20. return app.exec();
  21. }
To copy to clipboard, switch view to plain text mode 

Sami