我使用Maya 2016 + PyQt4.8
我创建了一个简单的窗口。它奏效了。但我希望对话可以停靠。
import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
import maya.cmds as cmds
#----------------------------------------------------------------------
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QObject)
#----------------------------------------------------------------------
class SetTreeOnSplines(QDialog):
def __init__(self, parent=getMayaWindow()):
super(SetTreeOnSplines, self).__init__(parent)
uic.loadUi('X:/tools/Maya/windows/2016/python/setTree.ui', self)
#----------------------------------------------------------------------
# window
def setTree():
formCollect = SetTreeOnSplines()
formCollect.show()
#----------------------------------------------------------------------
# MAIN
setTree()
如何使用PyQt修改脚本到对话框是否可停靠?
答案 0 :(得分:2)
import sip
import maya.OpenMayaUI as mui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
import maya.cmds as cmds
windowTitle = "Set_Tree_On_Splines"
windowObject = "SetTreeOnSplinesWinObject"
#----------------------------------------------------------------------
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QObject)
#----------------------------------------------------------------------
class SetTreeOnSplines(QDialog):
def __init__(self, parent=getMayaWindow()):
super(SetTreeOnSplines, self).__init__(parent)
uic.loadUi('X:/tools/Maya/windows/2016/python/setTree.ui', self)
self.setWindowTitle(windowTitle)
self.setObjectName(windowObject)
#----------------------------------------------------------------------
# window
def setTree():
if cmds.window(windowObject, q=True, exists=True):
print "Deleting ", windowObject
cmds.deleteUI(windowObject)
if cmds.dockControl( 'MayaWindow|'+windowTitle, q=True, ex=True):
print "Deleting ", 'MayaWindow|'+windowTitle
cmds.deleteUI( 'MayaWindow|'+windowTitle )
formCollect = SetTreeOnSplines()
cmds.dockControl( windowTitle, label=windowTitle.replace("_"," "), area='right', content=windowObject, allowedArea=['right', 'left'] )
#formCollect.show()
#----------------------------------------------------------------------
# MAIN
setTree()
我添加了两个变量(windowTitle
和windowObject
),它们用于在加载UI后设置窗口标题和窗口对象名称。
我还添加了一个检查,以查看窗口和可停靠区域是否已存在,以便删除它们。