Hi
I have a QLineEdit with a QRegExpValidator set. Now I want to allow my users to edit the string, e.g., insert characters in the middle of the string. How can I accomplish this?

Example: A QLineEdit with QRegExpValidator regExpValidator(QRegExp("I have (2 )?cats"), NULL); as validator allows to enter "I have cats". So far, so good. But: it should also allow to subsequently position the cursor in front of the 'c', then type '2', then space. It should allow to type '2' as the validation result should be QValidator::Intermediate because the expression might become valid when continuing to type at the cursor position. But apparently editing only works for appending text, not for inserting text; the second argument of QValidator::validate ( QString & input, int & pos ) const seems to be ignored (or only used as out parameter).

Is there a way to modify this behaviour? Thanks for any hint!

Al_

Complete application to test
Qt Code:
  1. #include <QRegExpValidator>
  2. #include <QLineEdit>
  3. #include <QApplication>
  4.  
  5. int main(int argc, char *argv[]){
  6. QApplication app(argc, argv);
  7. QLineEdit lineEdit(0);
  8. QRegExpValidator regExpValidator(QRegExp("I have (2 )?cats"), NULL);
  9. lineEdit.setValidator(&regExpValidator);
  10. lineEdit.show();
  11. return app.exec();}
To copy to clipboard, switch view to plain text mode