1

In the version of PySide2 that ships with Maya2017, the winId method on the QWindow class seems to be missing:

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

Is there a way to get this value from an existing instance of QWindow?

2 Answers2

0

I used Maya 2018 for macOS 10.11.6. Try this code. It works.

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() 

And after typing:

w.winId()

you'll get something like this:

# Result: 140640756092816 #

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
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.