我遇到了将modelEditor添加到QFrame的问题 如果可以的话,请帮助我。谢谢你
=>这是我在Qt Designer中创建的UI http://farm3.staticflickr.com/2944/15230904617_a2b8608d2d_b.jpg
import maya.OpenMayaUI as mui
import sip
from PyQt4 import QtGui, QtCore, uic
import maya.cmds as mc
import maya.mel as mm
def getMayaWindow():
# ‘Get the maya main window as a QMainWindow instance’
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
def toQtObject(mayaName):
”’
Given the name of a Maya UI element of any type,
return the corresponding QWidget or QAction.
If the object does not exist, returns None
”’
ptr = apiUI.MQtUtil.findControl(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findLayout(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findMenuItem(mayaName)
if ptr is not None:
return sip.wrapinstance(long(ptr), QtCore.QObject)
uiFile = (‘D:/modEditorTestUI.ui’)
form_class, base_class = uic.loadUiType(uiFile)
class myUIClass(form_class, base_class):
def __init__(self, parent=getMayaWindow()):
super(myUIClass, self).__init__(parent)
self.setupUi( self )
self.snapView = mc.modelEditor(displayAppearance=’smoothShaded’, displayTextures=True, wos=False, camera=’persp’)
qtObj = toQtObject(self.snapView)
print (‘qtObj: ‘ + str(qtObj))
#methods
self.connectSignals()
def connectSignals(self):
“”"Connect all the UI signals”"”
print “Connect signals”
def runUI():
global app
global win
app=QtGui.qApp
win = myUIClass()
win.show()
runUI()
答案 0 :(得分:1)
从你提供的代码片段看,由于最后一个if和return语句的缩进,toQtObject的方法看起来不会返回任何有用的东西。这是固定的:
def toQtObject(mayaName):
"""
Given the name of a Maya UI element of any type,
return the corresponding QWidget or QAction.
If the object does not exist, returns None
"""
ptr = apiUI.MQtUtil.findControl(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findLayout(mayaName)
if ptr is None:
ptr = apiUI.MQtUtil.findMenuItem(mayaName)
if ptr is not None:
return sip.wrapinstance(long(ptr), QtCore.QObject)