title: How can I prevent a graphic item from to be draw out the scene? and how to have different background colors for QGraphicsView and QGraphicsScene
body: <p>I want to set up like the image bellow.</p>
  
  <p>I want differents backgrounds color for <code>QGraphicsView</code> (say, same as window color) and <code>QGraphicsScene</code> (say, white). Also, I want that if some item is drawn out of the scene bounds that part is not rendered (the star 'any item' in img with legs cropped).</p>
  
  <p>I have no clue how to set up this. I'm new on Qt.</p>
  
  <p>PS: I'm using python, but you can examplify in c++ if you feel confortable.</p>
  
  <p><img src="https://i.stack.imgur.com/mldls.png" alt="enter image description here"></p>
  
  <hr>
  
  <p><strong>Answering Jeremy Friesner</strong></p>
  
  <p>This is my code applying your tips:</p>
  
  <pre><code>    scene = QtGui.QGraphicsScene(0, 0, 256, 256)
      scene.setBackgroundBrush(QtGui.QBrush(scene.palette().color(QtGui.QPalette.Window)))
      scene.addRect(scene.sceneRect(), QtGui.QPen(QtCore.Qt.NoPen), QtGui.QBrush(QtCore.Qt.white))
      scene.addLine(0, 0, 356, 356)
  
      view = QtGui.QGraphicsView(scene)
  
      self.setCentralWidget(view) # we are in a QMainWindow
  </code></pre>
  
  <p>As you can see, I add a white QRect using scene bounds and a line a bit bigger than the scene bounds. This is the screenshot result of my app (the line is drawn out the scene too):</p>
  
  <p><img src="https://i.stack.imgur.com/9dBFm.png" alt="enter image description here"></p>
  
  <p>If the app size is lesser than scene bounds (ie, <code>View &lt;= Scene</code>), the part out the scene is not rendered (bc scroll bars doesn't allow), but if the app is bigger (ie, <code>View &gt; Scene</code>), then it is drawn. How to solve that?</p>