My complex GUI consists of many native and custom widgets. Most of them has no focus at all (i don't need it: for example, some display-only widgets that doesn't need user's input).
Sometimes QLineEdit
appears on the screen when GUI want user to input some string (imagine window's Explorer after pressing F2 having some file selected (rename).
I want user to be able to close this QLineEdit
as many ways as possible: pressing Enter, ESC, clicking outside the QLineEdit.
QLineEdit
sends editingFinished()
signal in some circumstances (press Enter, click on another widget);QLineEdit
that sends editingFinished()
signal when focusOutEvent(QFocusEvent *)
occurs.editingFinished()
.The only problem is that QLineEdit
loses focus only if some another widget takes the focus. So if you click to a widget that doesn't care about focus, the QLineEdit
stay having focus and doesn't send the editingFinished()
signal.
You will probably need to install an event filter for your entire app, that sends a custom event to all your lineEdits
when a mouse click happens. And then in the lineEdit
, and implement QObject::event()
for your lineEdit
class checking for that custom event if it is active or has focus.
I wrote up an answer that points to the documentation for filters like this:
Catching Qt modifier key releases
Hope that helps.