title: QDialog won't stay on top of parent QMainWindow
body: <p>I'm trying to use Qt to make an <strong>option dialog that stays on top of the program's main window</strong> (which is a QMainWindow). QDialog seemed like a perfect fit, but clicking the main window would bring it back to the front. However, <strong>I have managed to make two tiny examples: one which works, and another which doesn't</strong> (which is derived from my actual application). I don't know what makes the behavior different between these two examples.</p>
  
  <hr>
  
  <p>The option window in the following example stays on top of the main window:</p>
  
  <p><code>test.cpp</code></p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QMainWindow&gt;
  #include &lt;QDialog&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication test(argc, argv);
      QMainWindow *mainWindow = new QMainWindow;
      mainWindow-&gt;show();
  
      QDialog * optionsWindow = new QDialog(mainWindow);
      optionsWindow-&gt;show();
  
      return test.exec();
  }
  </code></pre>
  
  <p><code>test.pro</code></p>
  
  <pre><code>TEMPLATE = app
  TARGET = test
  INCLUDEPATH += .
  QT = core gui widgets 
  
  SOURCES += test.cpp
  </code></pre>
  
  <hr>
  
  <p>The option window in the following example does <strong>not</strong> stay on top of the main window:</p>
  
  <p><code>TestApp.cpp</code></p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "MainWindow.hpp"
  
  int main(int argc, char *argv[])
  {
          QApplication testAppGUI(argc, argv);
  
          MainWindow *mainWindow = new MainWindow();
          mainWindow-&gt;show();
  
          return testAppGUI.exec();
  }
  </code></pre>
  
  <p><code>MainWindow.hpp</code></p>
  
  <pre><code>#ifndef MAINWINDOW_HPP
  #define MAINWINDOW_HPP
  
  #include &lt;QMainWindow&gt;
  #include "OptionWindow.hpp"
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
      public:
          explicit MainWindow(QWidget *parent = 0)
          {
              optionWindow = new OptionWindow(this);
              optionWindow-&gt;show();
          }
          OptionWindow *optionWindow;
  };
  
  #endif
  </code></pre>
  
  <p><code>OptionsWindow.hpp</code></p>
  
  <pre><code>#ifndef OPTIONWINDOW_HPP
  #define OPTIONWINDOW_HPP
  
  #include &lt;QDialog&gt;
  
  class OptionWindow : public QDialog 
  {
      Q_OBJECT
      public:
          explicit OptionWindow(QWidget *parent = 0){}
  };
  
  #endif
  </code></pre>
  
  <p><code>TestApp.pro</code></p>
  
  <pre><code>TEMPLATE = app
  TARGET = TestApp
  INCLUDEPATH += .
  
  QT = core gui widgets 
  
  HEADERS +=  MainWindow.hpp \
              OptionWindow.hpp
  
  SOURCES +=  TestApp.cpp
  </code></pre>
  
  <hr>
  
  <p><a href="https://stackoverflow.com/a/26316185/5776736">This SO answer</a> suggests giving the QDialog a parent, which I do. It also mentions setting the <code>Qt::Tool</code> flag, but it could not solve my problem (and the working example above doesn't use it).</p>
  
  <p><a href="https://stackoverflow.com/a/26066609/5776736">This other answer</a> suggests using a QDockWidget, but it doesn't meet my wanted visual style or expected behavior.</p>
  
  <p>Speaking of which, here's what I expect of my options dialog:</p>
  
  <ul>
  <li>The options window should always be on top of the main window, but not of the other applications;</li>
  <li>Only the main window shows in the taskbar;</li>
  <li>Minimizing the main window also minimizes the options window, and restoring it also restores the options window (on top of the main window);</li>
  <li>The main window should still be enabled when the options window is open.</li>
  </ul>
  
  <p>I am using QMake 3.1, Qt 5.8.0, g++ 5.4.0 and Xfce 4.12 on Linux Lite 3.4.</p>