Reputation: 21
I have a QDialog window that should always be on top of my application. It is NOT modal. The user can interact with the dialog and the main application at any time. Using WindowStaysOnTopHint accomplishes this to some degree. However, the dialog remains on top of all other running applications as well (ex. notepad, chrome, etc.). This can be annoying when constantly switching between applications.
I would like the QDialog to be on top of my application and no others. Any suggestions would be greatly appreciated.
Upvotes: 2
Views: 1552
Reputation: 2199
QDockWidget example using PyQt5:
w = MyDialog("test", parent) # Dialog that you want to be non modal.
d = QtWidgets.QDockWidget(parent) # parent needs to be a QMainWindow.
# make it floatable and give it a close button
d.setFeatures(QtWidgets.QDockWidget.DockWidgetFloatable | QtWidgets.QDockWidget.DockWidgetClosable)
# disable all dock areas so that can't dock
d.setAllowedAreas(Qt.NoDockWidgetArea)
d.setFloating(True)
d.setWidget(w)
d.show()
Upvotes: 0
Reputation: 702
Make sure that the QDialog's parent is your application window. If it has a NULL parent, then it doesn't know how to stack the two together.
Upvotes: 1
Reputation: 2102
QDockWidget is designed exactly for this. It's possible to configure it to float on top of your window.
Upvotes: 2