nin*_*o64 2 python pyqt maya pyside
我在maya中使用了PyQt4,通常我发现切换到PySide很容易,但是我无法获得指向主窗口的指针.也许有人可以理解出了什么问题.
这是我在PyQt4中所做的:
import sip, PyQt4.QtCore
import maya.OpenMayaUI as mui
ptr = mui.MQtUtil.mainWindow()
parent = sip.wrapinstance(long(ptr), PyQt4.QtCore.QObject)
Run Code Online (Sandbox Code Playgroud)
这很好用.当我在PySide中尝试相同时:
import sip, PySide.QtCore
import maya.OpenMayaUI as mui
ptr = mui.MQtUtil.mainWindow()
parent = sip.wrapinstance(long(ptr), PySide.QtCore.QObject)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
# Error: wrapinstance() argument 2 must be sip.wrappertype, not Shiboken.ObjectType
# Traceback (most recent call last):
# File "<maya console>", line 4, in <module>
# TypeError: wrapinstance() argument 2 must be sip.wrappertype, not Shiboken.ObjectType #
Run Code Online (Sandbox Code Playgroud)
谁知道出了什么问题?
qur*_*ban 12
您需要导入shiboken而不是sip传递QWidget给wrapInstanceQObject而不是QObject
编辑: Maya2017包含shiboken2和PySide2替代shiboken,并PySide在下面的评论中指出.
import shiboken
from PySide import QtGui, QtCore
import maya.OpenMayaUI as apiUI
def getMayaWindow():
"""
Get the main Maya window as a QtGui.QMainWindow instance
@return: QtGui.QMainWindow instance of the top level Maya windows
"""
ptr = apiUI.MQtUtil.mainWindow()
if ptr is not None:
return shiboken.wrapInstance(long(ptr), QtGui.QWidget)
Run Code Online (Sandbox Code Playgroud)
请注意,sip有wrapinstance在我是不是资本,但在shiboken.wrapInstance 我的资本.
shiboken.wrapInstance()需要包装类型作为第二个参数,因此您可以QWidget作为第二个参数传递.
| 归档时间: |
|
| 查看次数: |
7479 次 |
| 最近记录: |