title: Weird issue with QGraphicsScene
body: <p><strong>My objective:</strong>
        I want to draw a simple rectangle of length and breadth 100, at position x = 0, y = 0 on QGraphicsView. That should look something like this
  <a href="https://i.stack.imgur.com/0fVkl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0fVkl.png" alt="This is how I want"></a></p>
  
  <p><strong>What i have done so far</strong>
  I have created a object (on heap) called block_realiser in constructor of homepage(MainWindow), it accepts QGraphicsView as parameter in constructor. I created a QGraphicsScene (on heap) in block realiser constructor, and in its constructor itself I set this scene to the view. There is a function called drawRect in block_realiser that is supposed to draw a rect of 100x100 at (0,0).
  Code is</p>
  
  <pre><code>Block_Realiser::Block_Realiser(QGraphicsView *view, QObject *parent) :
      QObject(parent)
  {
      m_View = view;
      m_Scene = new QGraphicsScene;
      m_View-&gt;setScene(m_Scene);
  }
  
  void Block_Realiser::drawRect()
  {
      m_Scene-&gt;addRect(m_View-&gt;x(), m_View-&gt;y(),
                   100, 100);
  }
  </code></pre>
  
  <p>Now coming to my problem. There are two ways of calling the function drawRect in constructor of homepage. One is through timer (after 100 ms delay) and another is to call directly
  1) Through timer, code is </p>
  
  <pre><code>HomePage::HomePage(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::HomePage)
  {
      ui-&gt;setupUi(this);
      realiser = new Block_Realiser(ui-&gt;graphicsView);
  
      QTimer *timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), realiser, SLOT(drawRect()));
      connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()));
      timer-&gt;setSingleShot(true);
      timer-&gt;start(100);
  }
  </code></pre>
  
  <p>Output is </p>
  
  <p><a href="https://i.stack.imgur.com/nuTOi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nuTOi.png" alt="enter image description here"></a></p>
  
  <p>2) Calling function directly</p>
  
  <p>Code is </p>
  
  <pre><code>HomePage::HomePage(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::HomePage)
  {
      ui-&gt;setupUi(this);
      realiser = new Block_Realiser(ui-&gt;graphicsView);
      realiser-&gt;drawRect();
  }
  </code></pre>
  
  <p>Output is 
  <a href="https://i.stack.imgur.com/ynoEp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ynoEp.png" alt="enter image description here"></a></p>
  
  <p>So can anyone explain me what is going on in the above two cases? And how I can achieve my objective?. I have previously subclassed qwidget and reimplemented its paintEvent to achieve the same result of my objective. But this is not happening in qgraphicsscene. Please help me out. If any details missing, let me know.</p>