2

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?

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
TonyMJ
  • 51
  • 3

1 Answers1

1

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())
dlg.show()

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.

Vincent Bré
  • 4,090
  • 7
  • 23