2014-10-02 69 views
-1

我m到處問題補充modelEditor到QFrame 所以plz幫助我,如果你can.Thank你嵌入瑪雅modelEditor成PyQt的UI

=>以下是我的UI在Qt Designer創建 http://farm3.staticflickr.com/2944/15230904617_a2b8608d2d_b.jpg

這裏是代碼加載UI &添加功能

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

在你的代碼中,你甚至不試圖添加任何QFrame。有什麼問題? (你好,歡迎[so]) – 2014-10-06 15:38:58

+0

http://www.kurianos.com/wordpress/?p=692,http://nathanhorne.com/?p=381 – Achayan 2014-10-09 08:21:02

回答

1

從代碼片段您提供,它看起來像toQtObject不會回到任何有用的東西是方法最後一個if和return語句的縮進原因。這是固定的:

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)