View Full Version : Remove focus from GUI data field?

10 October 2010, 06:49 PM
When a custom GUI Window becomes active, the first data entry field (textField, intField, etc.) grabs the focus. Is there a way to prevent that?

10 October 2010, 07:23 PM
use setFocus, and set the focus to something else, like a button or the window itself.

10 October 2010, 10:50 PM
Thanks. That is helpful.
I have set it up to set the focus to a button using:
cmds.intField('numStart', w = 50, v = 1, enterCommand = 'cmds.setFocus("addParent")')

When I hit 'enter' the intField loses focus, however the "addparent" button seldom gets the focus, and if does, hitting 'enter' or 'return' does not activate the button (button press). Do you know if there is there a way to get that to work also?

10 October 2010, 11:05 AM
as the docs say: enterCommand ( is not executed when you enter the field but when you PRESS enter (that is NumPad enter!)

what you want is just a setFocus along with your UI creation, right?window;
textField -w 200;
textField -w 200 -text "focus is here! Yay!" myTextField2;
setFocus myTextField2;

10 October 2010, 11:07 AM
no eric, he wants it so that when he enters a value, it automatically sets focus to the BUTTON so he can immediately press Enter again (if desired) to activate or initiate whatever the UI does... I think :)

the problem is that buttons (in MEL UI) can't be pressed with Enter. (Space perhaps, if they have focus). I thinkl maybe he need's the prompt-dialog style of behaviour where Enter does actually accept/dismiss the dialog.. but I don't think standard (elf) UI buttons allow this behaviour.


CGTalk Moderation
10 October 2010, 11:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.