I found a solution that seems to work, although I'm still open to other options, if any. I am using PyQt4, so my example is in python:
Subclass QLineEdit so that I have a new type. I do not want or do not need this behavior in all instances of QLineEdit; only these specific ones.
class MyLineEdit(QtGui.QLineEdit):
pass
Now, in my subclass of QMainWindow, I am redefining the implementation mousePressEvent(). He is currently getting a widget. If this widget is of type MyLineEdit, clear focus.
class MyMainWindow(QtGui.QMainWindow):
def ...
def mousePressEvent(self, event):
focused_widget = QtGui.QApplication.focusWidget()
if isinstance(focused_widget, MyLineEdit):
focused_widget.clearFocus()
QtGui.QMainWindow.mousePressEvent(self, event)
def ...
This leads me to the behavior I'm looking for, so if the user clicks anywhere in the application window, the focus is cleared.
: . QTreeView . , .