title: How to center dialog on screen in QtQuick Controls 2?
body: <p>All my dialogs appear on the top left corner of screen instead of the center.</p>
  
  <p>What is the best way to let the dialogs be placed automatically correct?</p>
  
  <p><a href="https://i.stack.imgur.com/x5W94.png" rel="noreferrer"><img src="https://i.stack.imgur.com/x5W94.png" alt="enter image description here"></a></p>
  
  <pre><code>import QtQuick 2.7
  import QtQuick.Controls 2.2
  
  ApplicationWindow {
      id: mainWindow
  
      visible: true
      width: 640
      height: 480
      title: qsTr("Hello World")
  
      Component.onCompleted: {
          showMessageBox('Hey this actually works!');
      }
  
      function showMessageBox(message) {
          var component = Qt.createComponent("MessageDialog.qml")
          if(component.status == Component.Ready) {
              var dialog = component.createObject(mainWindow)
  
              dialog.title = qsTr("Information")
              dialog.text = message
  
              dialog.open()
          } else
              console.error(component.errorString())
      }
  }
  </code></pre>
  
  <p>With a very simple <strong>MessageDialog.qml</strong>:</p>
  
  <pre><code>import QtQuick 2.7
  import QtQuick.Controls 2.2
  
  Dialog {
      standardButtons: DialogButtonBox.Ok
  
      property alias text : textContainer.text
  
      Text {
          id: textContainer
  
          anchors.fill: parent
  
          horizontalAlignment: Qt.AlignLeft
          verticalAlignment: Qt.AlignTop
      }
  }
  </code></pre>