title: How to center a QMainWindow?
body: <p>I'm using Qt but I don't know how to center a QMainWindow window. I wrote this code, but it doesn't works. Thanks in advance.</p>
  
  <pre><code>QRect screenGeometry = QApplication::desktop()-&gt;screenGeometry();
  int x = (screenGeometry.width() - w-&gt;width()) / 2;
  int y = (screenGeometry.height() - w-&gt;height()) / 2;
  w-&gt;move(x, y); // w is a QMainWindow pointer
  </code></pre>
  
  <p>I get this:</p>
  
  <p><a href="https://i.stack.imgur.com/aMsIP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aMsIP.png" alt="enter image description here"></a></p>