I’ve never got
setWindowFlag to work before. Must be a relatively new development.
setWindowFlags (with an ‘s’) instead.
# in the dialog class
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowMinimizeButtonHint)
These are using bit flags, so the pipe ( | ) is a bitwise
“AND” “OR” that joins multiple flags together. If you want the maximize button to work as well you would use
QtCore.Qt.WindowMinMaxButtonsHint instead. The available options are found here
NOTE: In some versions of Maya you have to remind dialogs that they are windows with the
Qt.Window flag because they will function as widgets with no title bar after you parent them to the maya main window. That took me a while to figure out when I started. Also, the default appearance of dialogs does not have a min or max button so I’ve gotten used to setting what I want explicitly.
On the topic of parenting dialogs to maya, you might find this useful:
from PySide2 import QtWidgets
from maya.OpenMayaUI import MQtUtil
from shiboken2 import wrapInstance
""" Get Maya's Main Window as a QMainWindow """
window_ptr = MQtUtil.mainWindow()
return wrapInstance(long(window_ptr), QtWidgets.QMainWindow)
Then in your dialog class:
# parent the dialog to maya
# set up the dialog as a window with a minimize button
self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowMinimizeButtonHint)
Now the dialog will be on top of Maya, close / minimize with the application, and minimize to the bottom left corner like the script editor, node editor, or other editors do.