1

在 Maya2017 附带的 PySide2 版本中,winIdQWindow 类上的方法似乎丢失了:

w.winId()
Error: AttributeError: file <maya console> line 1: 'PySide2.QtGui.QWindow' object has no attribute 'winId' # 

有没有办法从现有的 QWindow 实例中获取这个值?

4

2 回答 2

0

Andy's example works for me in both Maya2018 and the latest release of Maya2017, but throws an exception in at least the initial release of Maya 2017.

I expect the problem was caused by a bug in PySide2 that got fixed along the way.

于 2017-09-20T23:15:53.487 回答
0

我将 Maya 2018 用于 macOS 10.11.6。试试这个代码。有用。

from maya import OpenMayaUI as omui 

try:
  from PySide2.QtCore import * 
  from PySide2.QtGui import * 
  from PySide2.QtWidgets import *
  from PySide2 import __version__
  from shiboken2 import wrapInstance 
except ImportError:
  from PySide.QtCore import * 
  from PySide.QtGui import * 
  from PySide import __version__
  from shiboken import wrapInstance 

mayaMainWindowPtr = omui.MQtUtil.mainWindow() 
mayaMainWindow= wrapInstance(long(mayaMainWindowPtr), QWidget) 

w = QLabel("Hello, Window", parent=mayaMainWindow) 
w.setObjectName('Label1') 
w.setWindowFlags(Qt.Window)
w.show() 

输入后:

w.winId()

你会得到这样的东西:

# Result: 140640756092816 #

在此处输入图像描述

于 2017-09-19T05:08:51.783 回答