title: PyQt4: Difference between QWidget and QMainWindow
body: <p>When reading through a PyQt4 tutorial, sometimes the examples uses <code>QtGui.QMainWindow</code>, sometimes it uses <code>QtGui.QWidget</code>.</p>
  
  <p><strong>Question:</strong> How do you tell when to use which?</p>
  
  <pre><code>import sys
  from PyQt4 import QtGui
  
  
  class Example(QtGui.QMainWindow):
  
      def __init__(self):
          super(Example, self).__init__()
  
          self.initUI()
  
      def initUI(self):               
  
          self.statusBar().showMessage('Ready')
  
          self.setGeometry(300, 300, 250, 150)
          self.setWindowTitle('Statusbar')    
          self.show()
  
  
  def main():
  
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>Another code example:</p>
  
  <pre><code>import sys
  from PyQt4 import QtGui, QtCore
  
  class Example(QtGui.QWidget):
  
      def __init__(self):
          super(Example, self).__init__()
  
          self.initUI()
  
      def initUI(self):      
  
          cb = QtGui.QCheckBox('Show title', self)
          cb.move(20, 20)
          cb.toggle()
          cb.stateChanged.connect(self.changeTitle)
  
          self.setGeometry(300, 300, 250, 150)
          self.setWindowTitle('QtGui.QCheckBox')
          self.show()
  
      def changeTitle(self, state):
  
          if state == QtCore.Qt.Checked:
              self.setWindowTitle('QtGui.QCheckBox')
          else:
              self.setWindowTitle('')
  
  def main():
  
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  
  
  if __name__ == '__main__':
      main()
  </code></pre>