Place non-modal QDialog window only on top of my application instead of all applications

无人久伴 提交于 2020-01-15 06:27:27

问题


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.


回答1:


QDockWidget is designed exactly for this. It's possible to configure it to float on top of your window.




回答2:


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.




回答3:


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()


来源:https://stackoverflow.com/questions/26064386/place-non-modal-qdialog-window-only-on-top-of-my-application-instead-of-all-appl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!