Getting pointer to qmainwindow returns nothing (maya2017+)

85 views
Skip to first unread message

Lidia Martinez

unread,
Jun 23, 2017, 11:47:12 AM6/23/17
to python_in...@googlegroups.com
I'm trying to setup a scriptJob for a Qt window. 
But in order to do that, I need the name of the window in the UI hierarchy.

You probably know, we can set the Object Name to a Qt object to get names for the windows 
|parentname|childname|...

instead of empty strings:
|||...



The problem with a QMainWindow, its central widget, or whatever widget you are trying to query, is that the path is not fully unique... and if you send that to the API, it returns an empty string or fails.

win = wdg.QMainWindow() // no matter if I assign a parent to the maya window
wdg.QWidget()
win.setCentralWidget(wdg.QWidget())
win.show()


The full name is always empty.

mui.MQtUtil.fullName(long(shiboken2.getCppPointer(win.centralWidget())[0]))

No matter what I do.

I know there must be a way to fix the hierarchy path to a window you create in Qt... it must be really easy.


Thanks!

--
Lidia

Alok Gandhi

unread,
Jun 23, 2017, 12:17:23 PM6/23/17
to python_in...@googlegroups.com
use uuid to give a unique name - '_' + uuid.uuid4().hex

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAAB1%3D8xYQHRZbuYsKz-EmT%2BRUaYrGh9NYgtdur-zk4ZYyMGKYw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--

oglop

unread,
Jun 23, 2017, 12:43:49 PM6/23/17
to Python Programming for Autodesk Maya
I thought you have to set object names before using that function ?

win.setObjectName('test object name')
widget.setObjectName('test widget name')

mui.MQtUtil.fullName(long(shiboken2.getCppPointer(win.centralWidget())[0]))
# Result: u'test object name|test widget name' #

Michael Boon

unread,
Jun 26, 2017, 3:55:20 AM6/26/17
to Python Programming for Autodesk Maya
Looking at your example code, there are a couple of things missing.
  • You don't set a parent for your QMainWindow. Without a parent, it doesn't have any hierarchy in the Maya UI. You've noted that you tried setting a parent, but maybe it didn't work? Can we see the code you tried?
  • You don't give either of your objects objectNames.
With no parent and no objectName, fullName will definitely return empty.
Reply all
Reply to author
Forward
0 new messages