[Interest] Finish QLineEdit editing when user clicks anywhere outside the QLineEdit
smurphy at walbro.com
Tue Aug 13 16:47:48 CEST 2019
I'm trying to create a custom QLineEdit where while editing, the user can click anywhere *outside* the QLineEdit to finish editing.
The default QLineEdit behavior appears to be that once the user has clicked inside the QLineEdit and begins editing the text, if the user then clicks on some other widget that *will* accept focus via a mouse click, the editing finished signal is emitted and the cursor/focus moves to whatever they clicked on. What I'm struggling with is that if the user clicks on something that *doesn't* normally accept focus via a mouse click, like any whitespace in my app, the cursor stays within the QLineEdit and editing is still active.
I thought maybe I could use focusOutEvent(), but in the case where the user clicks on whitespace, the QLineEdit doesn't receive a focusOutEvent(). So that doesn't appear to be useful, unless I'm missing something.
Ideally I want a solution that is completely contained within my custom QLineEdit-inherited class - with all the other widgets unaware that this behavior is happening. The only solution I'm finding via Google is doing things like installing event filters or setting the focus policy on other widgets to then force the QLineEdit to give up focus or end editing.
This message has been scanned for malware by Forcepoint. www.forcepoint.com
More information about the Interest