ruchit
I m getting problem to add modelEditor to QFrame So plz help me if you can.Thank you

=>Here is my UI created in Qt Designer http://farm3.staticflickr.com/2944/15230904617_a2b8608d2d_b.jpg

Here is code

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()
pshipkov
I don't think you can do that, or at least i don't know a way for that.

I don't know how complex the UI is going to be, but usually for single panel maya centric UIs i don't even bother with Qt. It way overcomplicates things for little benefit. :)
Reply 0 0
ruchit
Here is one example given by Nathan Horne for

Embedding a Maya widget into a PyQt UI

Reply 0 0
pshipkov
Yeah, that's a way.
Actually i hijack maya widgets like that all the time to install eventFilters.
At the time i replied didn't think that the same can be used to parent the hijacked widgets.
Reply 0 0
ruchit
Working Fine now.

Here is UI
snapUI.png 

Code:

import maya.OpenMaya as om
import maya.OpenMayaUI as omUI
import sip
from PyQt4 import QtGui, QtCore, uic
import maya.cmds as cmds
import maya.mel as mel
def getMayaWindow():
#    'Get the maya main window as a QMainWindow instance'
  ptr = omUI.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 = omUI.MQtUtil.findControl(mayaName)
    if ptr is None:
        ptr = omUI.MQtUtil.findLayout(mayaName)
    if ptr is None:
        ptr = omUI.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 )
    if mc.modelEditor('snapEditor', query=True, exists=True):
      mc.deleteUI('snapEditor', editor=True )
    self.snapView = mc.modelEditor('snapEditor', displayAppearance='smoothShaded', selectionHiliteDisplay=False, displayTextures=True, wos=False, camera='persp', imagePlane=False, nurbsCurves=False, lights=False, cameras=False, grid=False, joints=False, locators=False, headsUpDisplay=False)
    qtObj = toQtObject(self.snapView)
    
    self.p1_vbox = QtGui.QVBoxLayout(self.modelFrame)
    self.p1_vbox.addWidget(qtObj)
    qtObj.setMinimumSize(QtCore.QSize(256, 256))
    #self.setCentralWidget(qtObj)
    #methods
    self.connectSignals()
  def connectSignals(self):
    """Connect all the UI signals"""
    self.connect(self.snapshotBtn, QtCore.SIGNAL('released()'), self.takeSnap())
    
  def takeSnap(self):
    #Grab the last active 3d viewport
    mc.modelEditor('snapEditor', edit=True, activeView=True)
    view = omUI.M3dView.active3dView()
    
    #read the color buffer from the view, and save the MImage to disk
    image = om.MImage()
    view.readColorBuffer(image, True)
    image.writeToFile('D:/snapShot.jpg', 'jpg')
    
  
    
def runUI():
  global app
  global win
  app=QtGui.qApp
  win = myUIClass()
  win.show()
  
runUI()
Reply 1 0
pshipkov
Thanks for posting the code ruchit !
Reply 0 0
Reply