Aaron Wiginton
Aaron Wiginton

Reputation: 21

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

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

Answers (3)

glennr
glennr

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

Mike
Mike

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

Max Go
Max Go

Reputation: 2102

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

Upvotes: 2

Related Questions