title: PyQt4 Give Focus to Widget as it is called by the MainWindow and set as CentralWidget?
body: <p>I want to give Focus to a QLineEdit as soon as it appears... in other cases (all Widgets within the same class) it was possible with <code>.setFocus()</code> - but here this doesn't work.
  My candidates are <code>.activateWindow()</code>and <code>.raise_()</code>, but I couldn't figure it out how to use them.</p>
  
  <p>edit: My goal is to be able to type into the QLineEdit directly from the keyboard without the need to hit the <code>tab</code> key or click with the mouse in advance.</p>
  
  <p>Here an example of the relevant parts in question (functional):</p>
  
  <pre><code>import sys
  from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  
  class Quiz(QWidget):
      def __init__(self):
          QWidget.__init__(self)
  
          edit = QLineEdit("Select &amp; Focus")
          edit.selectAll()
          edit.setFocus()             # doesn't work - no effect at all
  
          vbox = QVBoxLayout()
          vbox.addWidget(edit)
          self.setLayout(vbox)
  
  
  class MainWindow(QMainWindow):
      def __init__(self):
          QMainWindow.__init__(self)
  
          startQuiz = QAction("Start Quiz", self)
          startQuiz.triggered.connect(self.startQuizQuestions)
  
          menubar = self.menuBar()
          quizMenu = menubar.addMenu("&amp;Quiz")
          quizMenu.addAction(startQuiz)
  
          self.setGeometry(300, 300, 500, 400)
          self.setWindowTitle("xyz")
          self.show()
  
      def startQuizQuestions(self):
          newQuiz = Quiz()
          self.setCentralWidget(newQuiz)
  
  
  def main():
      app = QApplication(sys.argv)
      window = MainWindow()
      window.show()
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>If you're seeing me terribly misusing Python or PyQt4... feel free to criticise, I want to learn.</p>
  
  <p>edit: I found in the <a href="https://deptinfo-ensip.univ-poitiers.fr/ENS/pyside-docs/PySide/QtGui/QWidget.html?highlight=setfocus#PySide.QtGui.PySide.QtGui.QWidget.activateWindow" rel="noreferrer">PySide Docs</a> for <code>.activateWindow</code> this discouraging "comment": "On Windows, if you are calling this when the application is not currently the active one then it will not make it the active window." - But I mean it IS the active Window (=MainWindow) it is just an other Widget in the CentralWidget of the active Window. (?)</p>