Here’s some handy debug code, this changes the tooltips for all the QWidgets in Maya to display their path, and QObject instance:

import sip
import maya.cmds as cmds
import maya.OpenMayaUI as apiUI
from PyQt4 import QtGui, QtCore
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)
#Set the tooltip for all widgets (This takes a little bit)
for widget in cmds.lsUI(dumpWidgets=True):
try:
qWidget = toQtObject(widget)
qWidget.setToolTip('(%s) %s'%(widget, qWidget))
except:
pass

Convert a wrapped pyqt object back to a Maya UI path:

apiUI.MQtUtil.fullName( sip.unwrapinstance(widget) )

Carlo Giesa said: 2011.06.27 00:13

Hi!
I just came across your post and wondered if you have any idea if something similar work also with Pyside. They don’t use sip to wrap the QObjects but there own library shiboken. But I could not figure out how I can convert my PySwig object that the MQtUtil class returns to a valid QObject for Pyside. Thanks for any hints or help!