In PySide2 application, how can I get the identifier for QWindow?

In the version of PySide2 that ships with Maya2017, the winId method in the QWindow class is 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 QWindow instance?

+1
source share
2 answers

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

 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 entering:

 w.winId() 

you will get something like this:

 # Result: 140640756092816 # 

enter image description here

0
source

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

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

0
source

Source: https://habr.com/ru/post/1273812/


All Articles