0

在其 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>]
4

1 回答 1

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 窗口的顶部。

于 2019-03-12T19:28:58.617 回答