QLineEdit losing focus when pressing the Shift-Key

I have a GUI that can float and also be docked. When the GUI is docked, my QLineEdit is losing focus whenever I press the Shift Key and the Mouse is outside the GUI extents.
I saw in the Bug Fixes for Maya 2014 that an issue with QLineEdits losing focus was addressed, however, it doesn’t seem to cover the case that QLineEdit is part of a Docked GUI.

Would be possible to install some kind of event filter on my QLineEdit to capture Shift Keys and FocusLost and restore Focus to the QLineEdit?

i had to subclass QLIneEdit to get maya not to steal focus, use it in place of QLineEdits


class LineEditSpaces(QtGui.QLineEdit):
    def keyPressEvent(self, event):
        key = event.key()
        if key == QtCore.Qt.Key.Key_Control or key == QtCore.Qt.Key.Key_Shift:
            pass
        else:
            super(LineEditSpaces, self).keyPressEvent(event)

A followup question out of laziness…
I have alot of UIs made in QtDesigner with lineEdits that have this problem… to avoid have to go through the hassle of creating a custom widget and getting it into QtDesigner, is there some kind of hack I can do per QMainWindow to trap the keys?

edit: found an answer maybe?
Since my UI was made in Qt Designer, it’s not trivial to replace all the line edits with custom line edits AFAIK…
so what i did was re-implement the keyPressEvent on the QMainWindow like so:


    def keyPressEvent(self, event):
        if event.key() in (QtCore.Qt.Key.Key_Shift, QtCore.Qt.Key.Key_Control):
            event.accept()
        else:
            event.ignore()

Does that work? As in, does it not break maya shortcuts, etc.?

while my UI has focus, Shift and Control will not be processed by the Maya Main Window, which stops the annoying change of focus. There may be unintended side-effects…

I know this is old, but figured i’d get it on the books: To fixup your line edits in the designer, right click > Promoted Widgets

In this window, give it the name of the class and the import string you’d use to get to it. So if your class is in /path/to/file.py and the class is MyLineEdit:

Promoted class name: MyLineEdit
Header file: path.to.file

It will ultimately result in a line at the end of the generated pythong file that looks like:

from path.to.file import MyLineEdit

Then you don’t have to muck around with it after you’ve loaded your ui file, everything is done in the deisgner