title: How to display a QMessageBox centered over its parent in PyQt4?
body: <p>I'm trying to display a QMessageBox centered over its parent, but it appears to display over its parent's parent. The following code generates 4 push buttons in a 2x2 grid. When a button is clicked, I'd like the corresponding message box to show centered on the button that was clicked (ie, the parent). However, it always shows up in the middle of the containing widget.</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  
  class ClickHandler(QtCore.QObject):
      def __init__(self, parent=None):
          super(ClickHandler, self).__init__(parent)
  
      def onClicked(self):
          sender = self.sender()
          print sender
  
          QtGui.QMessageBox.information(sender, 'onClicked', 'Using static method')
  
          mb = QtGui.QMessageBox(sender)
          mb.setWindowTitle('onClicked')
          mb.setText('Using object and exec')
          mb.exec_()
  
  if __name__ == '__main__':
      import sys
  
      app = QtGui.QApplication(sys.argv)
  
      ch = ClickHandler()
  
      layout = QtGui.QGridLayout()
      for i in xrange(4):
          pb = QtGui.QPushButton('button %d' % i)
          pb.clicked.connect(ch.onClicked)
          layout.addWidget(pb, i // 2, i % 2)
  
      w = QtGui.QWidget()
      w.setLayout(layout)
      w.resize(600, 600)
      w.show()
  
      sys.exit(app.exec_())
  </code></pre>
  
  <p>According to the QMessageBox docs:</p>
  
  <blockquote>
    <p>parent is passed to the QDialog constructor</p>
  </blockquote>
  
  <p>According to the QDialog docs:</p>
  
  <blockquote>
    <p>if it has a parent, its default location is centered on top of the parent</p>
  </blockquote>
  
  <p>Not sure what I am doing wrong or what I am missing. Any help would be appreciated.
  Thanks.</p>