Qt Designer python command?

Qt Designer python command?

laco727
Contributor Contributor
970 Views
6 Replies
Message 1 of 7

Qt Designer python command?

laco727
Contributor
Contributor
How can i add python command in Add Dynamic Property with Qt Designer.

Mel property with -command working ok, but how to python ?

thx
0 Likes
971 Views
6 Replies
Replies (6)
Message 2 of 7

vincent.rossini
Participant
Participant
Rasto,

I found myself in the same situation as you when trying to run Python commands, functions or methods through dynamic properties in QT designer.

I have discovered a workaround, however I'm by no means an expert with Python or QT so there are probably better ways to get this to work. At least for now you can do this by passing your command from MEL to Python with the help of the python command.

From what I read in the help docs, the python command allows users to execute Python commands from the MEL side.

-QT Designer-
1. Add a dynamic property String... to whatever widget you want.
2. For the property name use a MEL flag equivalent such as -command.
3. For the string add the python command in front of the command/function/method.

For example to create a polySphere I would write my string like so:
"python \"polySphere()\""


Add cmds. or pm. to the front of your commands if necessary:
"python \"pm.polySphere()\""


Or if I had already defined a function identified as go() I would use this as my string:
"python \"go()\""


Hope this helps :)
0 Likes
Message 3 of 7

Anonymous
Not applicable
For Python, just use +command instead of -command. If the dynamic property has a leading '+', it will be interpreted as a python flag.
0 Likes
Message 4 of 7

vincent.rossini
Participant
Participant
Thanks for your insight cgrebeld, this makes the whole process much more simple. :)
0 Likes
Message 5 of 7

laco727
Contributor
Contributor
cgrebeld thx, thats what i am looking for.

Now i am fighting with this:

test.py

import maya.cmds as cmds

def run():
print 'Function is ok.'


+command:

__file__.run() or test.run() or ?
0 Likes
Message 6 of 7

laco727
Contributor
Contributor
yes, but its hard way, i wana go around. :) thx
0 Likes
Message 7 of 7

Anonymous
Not applicable
If test is imported before you run loadUI, then
+command:
"test.run()"

should work or:
+command:
test.run

If it isn't imported then use:
+command:
"import test;test.run()"
0 Likes