I can’t speak for Linux behavior, but to get Maya tools set up correctly on Windows I have to do 2 things:
- Parent the tool dialog to the Maya main window
- Set the dialog’s window flags to either
QtCore.Qt.Tool, depending on the look you want. I always prefer the former for anything other than small confirmation dialogs.
My code usually looks something like this
from PySide2 import QtCore, QtGui, QtWidgets
import maya.OpenMayaUI as omui
from shiboken2 import wrapInstance
main_window_ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(main_window_ptr), QtWidgets.QMainWindow)
def __init__(self, parent=getMayaMainWindow()):
if __name__ == '__main__':
dialog = MyDialog()
I’ve not had any issues with custom dialogs since I started setting them up this way.
If you have issues with the dialog not appearing at the center of the screen, you can center it when showing the UI. I prefer to override QDialog’s show method for this, since it will have to happen after any widget creation that can change the dimensions of the dialog, and that include’s QtDialog’s
show() method. Here’s an example:
# you can use this method or max's method
def centerWindowOn(childWindow, parentWindow):
# def __init__() ...
# if you don't do this last, you won't get the result you expect!
I find it very useful to create a library for functions like
centerWindowOn since they tend to be used very often. It also cuts down on the number of import statements you have to write to get something simple working.