As far as I understand, a validator can return three results: Invalid, Intermediate and Acceptable. Suppose my line edit has a regexp validator set with the following regular expression:
[ab][cd]
So, valid values are: ac
, ad
, bc
, bd
:
If I try to enter any other character, such as e
or 0
, the line edit will not let me enter it physically. However, if I enter a
and switch to another control, it will have no problems with it, although the value a
is not acceptable, but rather, intermediate.
Here's what I am after. I want the line edit to refuse me to switch focus to any other control if its input is not acceptable. That is, I need to enter a line which fully satisfies my regular expression so that I can switch focus. Otherwise I want my form/dialog etc to refuse me the ability to switch focus.
Is there a straightforward one-liner way to do this or do I have to do this manually? If the latter, what's the standard way of doing this?
There is a QApplication::focusChanged() signal. You can catch that, and explicitly check in it if the result for your widget is valid or intermediate, and take suitable action.
I am not aware of a one-liner solution, but it might still exist. My solution is a bit more manual.