title: Make widget as big as possible
body: <p>Here is some code I've written (and/or adapted from other sources):</p>
  
  <pre><code>import numpy as np
  from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  from matplotlib.figure import Figure
  from PyQt5.QtWidgets import (QGraphicsView, QGraphicsScene, QMainWindow,
                               QApplication, QWidget, QVBoxLayout, 
                               QDesktopWidget)
  from PyQt5.QtGui import QBrush
  from PyQt5.QtCore import Qt
  import sys
  
  class View(QGraphicsView):
  
      def __init__(self):
          super(View, self).__init__()
  
          self.initScene()
  
      def initScene(self):     
  
          self.scene = QGraphicsScene()
          self.canvas = Fig()
          self.setBackgroundBrush(QBrush(Qt.red))
          self.canvas.draw()
          self.setScene(self.scene)
          self.scene.addWidget(self.canvas)
  
  class Fig(FigureCanvas):
  
      def __init__(self, *args,**kwargs):
          self.factor = kwargs.pop("factor", 2)
          FigureCanvas.__init__(self, Figure(), *args,**kwargs)
          self.plot()
  
      def plot(self):
          self.ax = self.figure.add_subplot(111)
          data = np.random.rand(1000)
          self.ax.plot(data, '-')
  
  
  class Window(QMainWindow):
  
      def __init__(self):
  
          QMainWindow.__init__(self)
  
          desktop = QDesktopWidget()
          rect = desktop.availableGeometry()
          self.setGeometry(rect.width()/10, rect.height()/10, rect.width()/1.2,
                     rect.height()/1.2)
  
          self.view = View()
          self.setCentralWidget(self.view)
  
  app = QApplication(sys.argv)
  window = Window()
  window.show()
  app.exec_()
  </code></pre>
  
  <p>It produces the following window as its output:
  <a href="https://i.stack.imgur.com/u5Cje.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u5Cje.png" alt="enter image description here"></a></p>
  
  <p>I would like the plot in the middle to occupy as much space as possible, so that the red background becomes invisible.</p>
  
  <p>This happens if I exclude the command setting the size of the window, that is indeed what happens. However, the window is then too small - I need to make it bigger. </p>
  
  <p>I have tried using <code>self.view.setGeometry</code>, but it doesn't seem to make a difference. I've had a look at the available modules in the <a href="http://doc.qt.io/qt-5/qgraphicsview.html" rel="nofollow noreferrer">documentation</a>, but can't tell which might help.</p>