title: How can I show/hide background drawing on QGraphicsScene or QGraphicsView?
body: <p>I would like to have certain things drawn on QGraphicsScene, but not be QGraphicsItem (it would interfere with the processing of the <code>QGraphicsItem</code> collection).</p>
  
  <p>Example: a scene bounding rectangle, a grid</p>
  
  <p>I am overriding the <code>drawBackground(QPainter *painter, const QRectF &amp;rect)</code> for that purpose. (I should subclass the scene... )</p>
  
  <pre><code>void MyView::showHideBounds()
  {
      m_showBackgroundBounds = !m_showBackgroundBounds;
      // can't triger an update ???
      update(); // neither does anything
      viewport()-&gt;update();
  }
  
  void MyView::drawBackground(QPainter *painter, const QRectF &amp;rect)
  {
      QPen pen;
      if(m_showBackgroundBounds)
          pen = QPen(QColor(0, 0, 0), 10, Qt::PenStyle(Qt::SolidLine));
      else
          pen = QPen(QColor(255, 255, 255), 10, Qt::PenStyle(Qt::SolidLine));
  
      painter-&gt;setPen(pen);
      painter-&gt;drawRect(QRect(QPoint(-scene()-&gt;sceneRect().size().toSize().width()/2,
                                     -scene()-&gt;sceneRect().size().toSize().height()/2),
                              scene()-&gt;sceneRect().size().toSize()));
  }
  </code></pre>
  
  <p>I would like the option to <strong>show/hide</strong> either the bounding rectangle or the grid. </p>
  
  <p>The only thing I can think of is paint over them with the color of the background brush ? Is there any other option ? </p>
  
  <p>As I have written it above, it works - except I need user action on items (or a zoom or some other scene changing action) to trigger refresh, or call an update... (the function  <code>showHideBounds</code> doesn't - not sure how to make it force a refresh)</p>
  
  <p>I would call the <code>drawBackground</code> from the  <code>showHideBounds</code> function - but I don't know how to get the <code>painter</code></p>
  
  <p>[Also, the <code>drawBackground</code> seems to be drawn automatically... how can I give it the <code>rect</code> argument it needs ? (it seems if I draw the <code>rect</code> it does draw the scene rectangle but I only see the right and bottom edges)]</p>