Get maya UI position in screen space

88 views
Skip to first unread message

Zhen Huang

unread,
Jun 18, 2018, 10:12:14 PM6/18/18
to Python Programming for Autodesk Maya
Hi ,

It's there a solution to get maya UI position in screen space .

''' UI
import maya.cmds as mc
mc.window()
mc.columnLayout(adj = 1)
mc.button('testButton')
mc.shwWindow()

'''

There is a discussion about the windows UI in screen space . 

And I tried it for a button UI , it seems a local position under the layout :
'''
import maya.OpentMayaUI as mui
from PySide2 import QtWdigets
import shiboken2
prt = mui.MQtUtil.findControl('testButton')
qwidget = shiboken2.wrapInstance(long(ptr) , QtWidgets.QWdiget)
print qwidget.x()
print qwidget.y()
'''


Thanks , 

Justin Israel

unread,
Jun 18, 2018, 10:18:08 PM6/18/18
to python_in...@googlegroups.com
You are almost there. The x()/y() are local coordinates relative to its parent. You can get the position and map it to global (screen coordinates):

qwidget.mapToGlobal(qwidget.pos())


Justin

 

Thanks , 

--
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_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9029d150-4e98-4f10-b91b-c0939a3efe11%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zhen Huang

unread,
Jun 20, 2018, 3:51:44 AM6/20/18
to Python Programming for Autodesk Maya
Hi Justin , 

Thanks you so much , it's awesome to be help so soon .

update code here because I spell wrong in few lines:

'''
import maya.cmds as mc
mc.window()
mc.columnLayout(adj = 1)
mc.button('testButton')
mc.showWindow()

import maya.OpentMayaUI as mui
from PySide2 import QtWidgets
import shiboken2
prt = mui.MQtUtil.findControl('testButton')
qwidget = shiboken2.wrapInstance(long(ptr) , QtWidgets.QWidget)

qwidget.mapToGlobal(qwidget.pos())

'''






Best Regards ,

在 2018年6月19日星期二 UTC+8上午10:18:08,Justin Israel写道:


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages