'How view gets fully visible in scene in Qt?

I am having QGraphicsView, which has multiple QGraphicsItem's. When my design loads first time and gets visible on screen, it can not be fit fully in the screen. Around 80% of view gets visible. Then I need to use scrolling to see the remaining 20% of the view.

How my whole design will get visible at the time of loading ?

myClass::myClass(QWidget* parent) :
    QDockWidget(parent)

{
   hide();
   QWidget* newWidget = new QWidget();
   QBoxLayout* tLayout = new QBoxLayout(QBoxLayout::TopToBottom,newWidget );
   tLayout->setContentsMargins(0, 0, 0, 0);

   QLabel *label = new QLabel("My Window",this);
   this->setTitleBarWidget(label);
   tbar = new QToolBar;
   tbar->setIconSize(QSize(35,35));
   tbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
   tLayout->addWidget(tbar,0,Qt::AlignTop);          

   QGraphicsScene* scene = new QGraphicsScene(this);
   QGraphicsView* view = new QGraphicsView(this);
   view->setScene(scene);             

   tLayout->addWidget(view);
   newWidget ->setLayout(tLayout);

   bar = new QStatusBar();
   bar->showMessage(tr("Ready"));
   this->setWidget(bar);

   setWidget(newWidget);
}  

I was told , how to proceed ( but not sure I understood properly ) : 1st find out the points through scene->sceneRect() then take 2 points , top right and bottom left and use some margin function and add some margin to it and then give those 2 points to ensureVisibility() which will make visible those points.
How to achieve this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source