Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Maya & PyQt: how to prevent trigger of shortcut keys?

5 REPLIES 5
Reply
Message 1 of 6
sponcik
2804 Views, 5 Replies

Maya & PyQt: how to prevent trigger of shortcut keys?

I have PyQt script running from within Maya. Problem is that Maya short-cut keys get triggered when users make entries in text fields of my UI. For example, if user types <shift> <f> for an uppercase F, the Maya viewport will do a "Frame all" instead of just entering upper case F in the text field.

Is there a setting I need for my PyQt window class? I am using Maya 2013.

 

Thanks!

5 REPLIES 5
Message 2 of 6
cyrille
in reply to: sponcik

Hi

 

I just tried with this code with no problem

what version of PyQt are you using and do you got a small example?

 

cheers

cyrille

 

import sys
from PyQt4 import QtGui

class Example(QtGui.QWidget):

  def __init__(self):
    super(Example, self).__init__()
    self.initUI()

  def initUI(self):
    self.btn = QtGui.QPushButton('Dialog', self)
    self.btn.move(20, 20)
    self.btn.clicked.connect(self.showDialog)

    self.le = QtGui.QLineEdit(self)
    self.le.move(130, 22)

    self.setGeometry(300, 300, 290, 150)
    self.setWindowTitle('Input dialog')
    self.show()

  def showDialog(self):
    text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter your name:')
    if ok:
      self.le.setText(str(text))

ex = Example()

 

Message 3 of 6
jsb_dneg
in reply to: cyrille

Hi Cyrille,

 

We have also encountered this with Maya 2014. It seems to occur for any QWidget but some specific conditions are required to repro:

 

1. Launch Maya 2014

2. Make sure both the outliner and the viewport is visible in the main window

3. Select an object in your scene using the outliner (for me, the default |persp works)

4. Display any Qt UI - for me running the following code in the Python script bar works:

        from PyQt4 import QtGui ; w = QtGui.QWidget( ) ; w.show()

 

5. Move the widget such that it is on top of the Maya viewport

6. Make sure the widget is on top and has focus

7. Make sure your cursor is above your window AND above the viewport (hidden by your widget)

8. Press SHIFT

 

Pressing SHIFT should return focus back to the Maya main window.

 

For us, this becomes a real problem in any of our Qt UIs where the artist has to type something in - under the above conditions, as soon as they need to type a capital letter, they hit SHIFT, focus is returned back to Maya, and the next keystroke they press will then be applied to the Maya window instead of our UI, which causes all kinds of crazyness in their scenes!

 

Some further details: we are able to repro the above in a plain version of Maya 2014 without any of our own software loaded. We're running on Linux, and this seems to happen regardless of OS focus settings.

 

Please let me know if you're able to repro this using the above steps - it would be great to know whether you're able to repro it, and also, which version of Maya is likely to receive a fix...

 

Thanks,

 

James.

Message 4 of 6
philsloggett
in reply to: jsb_dneg

 Hey James I think I've found a workaround. I say "think" because I havent worked with it much yet to know if there are caveats.

 

Basically, just override the keyPressEvent on your "top most widget" (by which I mean the parent widget of your tool which will probably, in turn, be parented to maya's main window).

 

Do whatever you want in this method (I just left a 'pass', my top widgets are usually pretty useless), but whatever you do, do not call the superclass' keyPressEvent. This seems to stop the event propagation back in to maya.

 

All your child widget's keypress behaviour and event-propagation should be unaffected, so the internal workings of your tool should be fine.

 

Let me know if you have a problem with this method because I'd like to know about it too!

 

Phil

Message 5 of 6
danielkenobi3d
in reply to: sponcik

I have the exact same problem o max, did you resolve this issue at the end? 

Regards Daniel 

Message 6 of 6
philsloggett
in reply to: sponcik

Other people have since confirmed my suggestion worked for them, I'd try that Daniel. Override the keypress event on some parent widget to prevent event propagation back to maya.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report