2

I have made the UI of a qgis plugin using qt creator. What I want is that the plugin window should stay on top of the qgis main window only but not other other applications. I have got this code:

    QtGui.QDialog.__init__(self, None, Qt.WindowStaysOnTopHint)

But the problem is that after implementing this code the plugin window stays on top of every other application as well.

1 Answer 1

2

you have to give your Dialog a parent. If you would construct a QDialog in console you give the main window of the QGis Application as parent and you dont add a Windows Hint.

from PyQt4 import QtGui
dlg = QtGui.QDialog(iface.mainWindow())
dlg.show()

After this the Dialog is centered on top of the parent (QGis Application) and not on top off all applications. In your case you have to replace the 'None' value for the parent with the main window of the QGIS Interface.

2
  • Thanks for the answer. I simply replaced the "None" with "iface.mainWindow" and removed the "Qt.WindowStaysOnTopHint" flag and it works perfectly fine for me :)
    – Farhan
    Commented Nov 23, 2015 at 7:17
  • 1
    Hey I have got another problem. After assigning the parent to my plugin window all of its formatting e.g font size and bold is gone. I think it is get the default values from the parent window. Any ideas on how to keep the custom formatting define in the Ui file?
    – Farhan
    Commented Nov 25, 2015 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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