Searching for QPushButton, a-la lsUI ?

61 views
Skip to first unread message

AK Eric

unread,
Mar 19, 2015, 2:03:07 PM3/19/15
to python_in...@googlegroups.com
Created a .ui file in QtDesigner, it shows up happily in Maya via loadUI.

I have other Maya code (based on lsUI) that can search through controls related to buttons, and report stuff like their label, annotation, command, etc.
However, it appears that lsUI ignores anything created from a .ui file.
I know the corresponding Maya controls do exist.  For example, I have a named QPushButton in qtDesigner called 'myButton'.  This works in Maya:

import pymel.core as pm
b = pm.ui.Button('myButton')
print b
print b.getLabel()

But again, lsUI ignores the existence of the corresponding Maya button.

Any thoughts on how to say, just list every QPushButton in Maya?  I can sort from there.  Or any other ideas?

thanks

Justin Israel

unread,
Mar 19, 2015, 3:56:54 PM3/19/15
to python_in...@googlegroups.com
I don't remember why you would be seeing inconsistent behaviour, but I feel like it is related to the oddness that can happen with Qt widget objectNames and how they are added to layouts, and whether Maya translates them properly to controls, etc, etc. 

Anyways, you could just access them through the Qt API instead if you want, and not worry about what Maya does and does not recognize?
from PySide import QtGui
import shiboken

import maya.OpenMayaUI as mui

win = shiboken.wrapInstance(long(mui.MQtUtil.mainWindow()), QtGui.QWidget)
print win.findChildren(QtGui.QPushButton)

Justin



--
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/09b577ae-2418-4438-a281-e09ed411eb3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AK Eric

unread,
Mar 21, 2015, 9:39:03 PM3/21/15
to python_in...@googlegroups.com
Thanks Justin : lol, I'd forgot I'd posted this and ended up coming up with the exact same solution.  Which works great by the way.
I'm still pretty new to the whole "let's load a .ui file and play with it thing", but I've done tests where in QtDesigner I will create say, a QPush button with a given name:  lsUI won't find it, but if I query it with the Maya button command by name, I can do stuff to it.
Innnncoonnnssisteeennntt....
:S

Justin Israel

unread,
Mar 21, 2015, 10:05:08 PM3/21/15
to python_in...@googlegroups.com

Glad to hear you solved it.
The whole integration of Qt widgets with the legacy Maya commands api is a bit if a grey area to me. They map them under the hood to whatever the native UI concepts were. It is usually best to try and avoid all UI commands, if you can help it, when you have committed to a Qt interface. Also I see that Qt Designer file support as kind of a gimmick. Or at least a really easy way for someone to transition into Qt in Maya. They have those features for a named button automatically wiring up to named callbacks if you use the right +/- syntax. But ultimately you might come to find that there is only so much you can do with that. Ends up being easier to just write a few lines of Qt UI code directly, and have full access through the Qt API. No UI files or Maya native UI commands to muck with.


--
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.
Reply all
Reply to author
Forward
0 new messages