如何使对话窗口保持在Maya / Motionbuilder父程序之上?

时间:2018-03-26 23:26:49

标签: python pyside maya qdialog motionbuilder

我试图在Python编辑器控制台中运行此代码后,在父Maya或Motionbuilder程序之上保留一个对话框窗口,但我似乎无法理解。现在,窗口将保持在一切的顶部,这不是我想要的。我只想把它放在父3D程序窗口之上。

以下是代码:

from PySide import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 300)

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))

class Dialog(QtGui.QDialog, Ui_Dialog):
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)
        self.setupUi(self)

if __name__ in ('__main__', '__builtin__'):
    app = QtGui.QApplication.instance()
    print(app.topLevelWidgets())
    if app is None:
        app = QtGui.QApplication([])
    w  = Dialog(app.topLevelWidgets()[0])
    w.show()
    app.exec_()

打印输出(app.topLevelWidgets()):

[<PySide.QtGui.QMenu object at 0x0000000032F97348>, <PySide.QtGui.QWidget object at 0x0000000032F97388>, <PySide.QtGui.QWidget object at 0x0000000032F973C8>, <PySide.QtGui.QMenu object at 0x0000000032F97408>, <PySide.QtGui.QWidget object at 0x0000000032F97448>, <PySide.QtGui.QMenu object at 0x0000000032F97488>, <PySide.QtGui.QWidget object at 0x0000000032F974C8>, <PySide.QtGui.QWidget object at 0x0000000032F97508>, <PySide.QtGui.QWidget object at 0x0000000032F97548>, <PySide.QtGui.QMenu object at 0x0000000032F97588>, <PySide.QtGui.QWidget object at 0x0000000032F975C8>, <PySide.QtGui.QMenu object at 0x0000000032F97608>, <PySide.QtGui.QWidget object at 0x0000000032F97648>, <PySide.QtGui.QWidget object at 0x0000000032F97688>, <PySide.QtGui.QWidget object at 0x0000000032F976C8>, <PySide.QtGui.QWidget object at 0x0000000032F97708>, <PySide.QtGui.QWidget object at 0x0000000032F97748>, <PySide.QtGui.QMenu object at 0x0000000032F97788>, <PySide.QtGui.QMenu object at 0x0000000032F977C8>, <PySide.QtGui.QWidget object at 0x0000000032F97808>, <PySide.QtGui.QWidget object at 0x0000000032F97848>, <PySide.QtGui.QWidget object at 0x0000000032F97888>, <PySide.QtGui.QMainWindow object at 0x0000000032F92EC8>, <PySide.QtGui.QWidget object at 0x0000000032F978C8>, <PySide.QtGui.QMenu object at 0x0000000032F97908>, <PySide.QtGui.QMenu object at 0x0000000032F97948>, <PySide.QtGui.QMenu object at 0x0000000032F97988>, <PySide.QtGui.QMenu object at 0x0000000032F979C8>, <PySide.QtGui.QWidget object at 0x0000000032F97A08>, <PySide.QtGui.QMenu object at 0x0000000032F97A48>, <PySide.QtGui.QMenu object at 0x0000000032F97A88>, <PySide.QtGui.QMenu object at 0x0000000032F97AC8>, <PySide.QtGui.QWidget object at 0x0000000032F97B08>, <Dialog object at 0x0000000032F92F88>, <PySide.QtGui.QWidget object at 0x0000000032F97B48>, <PySide.QtGui.QMenu object at 0x0000000032F97B88>, <PySide.QtGui.QMenu object at 0x0000000032F97BC8>, <PySide.QtGui.QMenu object at 0x0000000032F97C08>, <PySide.QtGui.QWidget object at 0x0000000032F97C48>, <PySide.QtGui.QWidget object at 0x0000000032F97C88>, <PySide.QtGui.QMenu object at 0x0000000032F97CC8>]

1 个答案:

答案 0 :(得分:0)

import maya.OpenMayaUI as OMUI
import shiboken2

import PySide2.QtCore as QtCore
import PySide2.QtWidgets as QtWidgets

class YourWindowClass(QtWidgets.QWidget):
    def init(self):
        super(YourWindowClass, self).init()

        # get Maya's main window
        self.mayaWin = OMUI.MQtUtil.mainWindow() 
        self.mayaWin = shiboken2.wrapInstance(long(self.mainWin), QtWidgets.QWidget)

        # parent your window to Maya's main window
        self.setParent(self.mayaWin, QtCore.Qt.WindowStaysOnTopHint)

#这应仅将“ WindowStaysOnTopHint”标志应用于窗口的父窗口(此处为Maya的主窗口),
#但必须严格:大纲视图面板和其他面板将停留在窗口的顶部,因为它们位于Maya窗口的顶部...