I want to keep a modeless dialog window on top of the main QGIS window. This issue has been discussed before and two solutions have been offered:

  1. self.dlg.setWindowFlags(Qt.WindowStaysOnTopHint). This is unsatisfactory because the dialog window stays on top of every application window, not just the QGIS one.
  2. Give the dialog an owner when it is created, as in self.dlg = MyCreatorDialog(self.iface.mainWindow()). This does indeed keep the dialog on top of the application's main window, but sets the dialog as modal, so the underlying window is inaccessible.

The processing toolbox creates modeless dialog boxes that stay on top of the application window, but not on top of other applications. How does it do it?


When I run the following code in the Python console of QGIS, the dialog window has the same behavior as the dialog windows in the processing toolbox.

dlg = QDialog(iface.mainWindow())

You can achieve this by giving the dialog a parent (here, the main window of QGIS).

A child dialog always stays on top of its parent window.

| improve this answer | |
  • Sorry, should have mentioned that I'm running this from a plugin that I'm writing. Obviously the behaviour is different from the console. – TonyMJ Jun 23 at 8:57
  • The result generated by the console is what you're expecting? – Vincent Bré Jun 23 at 9:03
  • Yes, that's exactly right. Modeless and on top.But doing that from a plugin makes the dialog modal. Maybe I have to reset it to modeless after creating it. – TonyMJ Jun 23 at 9:09
  • I'm trying to look in the day or tomorrow. – Vincent Bré Jun 23 at 9:11
  • Solved it! I was using dlg.open(), but if I use dlg.show() it works perfectly - modeless and on top. – TonyMJ Jun 23 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.