2016-03-14 100 views
-1

我使用Maya 2016 + PyQt4.8PyQt在Maya中的可停靠窗口

我创建了一个简单的窗口。它的工作。但我想让对话框可以停靠。

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的对话框是可停靠的?

回答

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() 

我添加了两个变量(windowTitlewindowObject),它们被用来设置窗口的标题,并且一旦UI加载窗口对象名称。 我还添加了一个检查来查看窗口和可停靠区域是否已经存在以便删除它们。

+0

其对接。 TNX。但函数closeEvent(self,evnt)停止工作... – MaxKu

+0

和函数self.geometry()返回[0,0,w,h] - 0,0到位置窗口... – MaxKu

+0

使用可停靠的小部件,我相信你必须改用'dockCloseEventTriggered'。 –