title: How to set Brush of QGraphicsRectItem in QGraphicsScene
body: <p>I am trying to set Brush of 5 QGraphicsRectItem by setBrush using QBrush. but it doesn't work. The behavior is confusing as it works in some cases.</p>
  
  <p><img src="https://i.stack.imgur.com/h9lYq.jpg" alt="example image"></p>
  
  <p>The code includes a *.ui which I have created in Qt-Creator. I have added a QGraphiocsView on it.</p>
  
  <pre class="lang-js prettyprint-override"><code>QGraphicsScene *scene_;
  
  scene_ = new QGraphicsScene(ui-&gt;graphicsView);
  ui-&gt;graphicsView-&gt;setScene(scene_);
  
  scene_-&gt;setBackgroundBrush(Qt::red);
  
  
  for (int i=0; i&lt;5; i++)
  {
      QBrush tmpBrush;
      tmpBrush.setColor( QColor(200-i*15, i*15, 50) );
      QPen tmpPen;
      tmpPen.setColor(Qt::blue);        tmpPen.setWidth(2);
  
      QGraphicsRectItem*tmpRect = scene_-&gt;addRect( 2, 25*i, 100, 20, tmpPen, tmpBrush );
      tmpRect-&gt;setPen(tmpPen);          tmpRect-&gt;setBrush(tmpBrush);
  }
  </code></pre>
  
  <p>I'm coding with QT 5.7 in Ubuntu 16.04.</p>