无法使用掩码和验证器删除 QlineEdit 中的文本
我写了一个手机QRegExp验证器,将其添加到LineEdit中。另外,我还加了一个面具。 (经过几次错误后,我意识到必须在验证器之后添加掩码,否则什么都不适合) 验证器(QRegExp):
QRegularExpression numberRegex ("^\\+\\d{1,1}\\(\\d{1,3}\\)\\d{1,3}\\-\\d{1,2}\\-\\d{1,2}$");
QRegularExpressionValidator *numberValidator = new QRegularExpressionValidator (numberRegex);
为 QLineEdit 添加掩码和验证器本身的代码:
ui->lineEdit_4->setValidator(numberValidator);
ui->lineEdit_4->setInputMask("+7(000)000-00-000");
一切正常,数字以正确的形式输入,但是有一个问题:写数字时,我可以通过按(退格)擦除,但是输入最后一个字符后,我无法再擦除了。
UPD:如果我制作一个末尾带有附加“0”的蒙版,那么所有内容都会被删除,但它不再适合我需要的蒙版。 TOTAL:如果掩码和验证器“重合”,则在写入结束时无法擦除 UPD2:如果我单击 ALT+Shift 最后 2 个符号无论如何都会被删除
I wrote a mobile phone QRegExp validator, added it to LineEdit. In addition, I added a mask. (After several mistakes, I realized that the mask must be added after the validator, otherwise nothing fits) Validator (QRegExp):
QRegularExpression numberRegex ("^\\+\\d{1,1}\\(\\d{1,3}\\)\\d{1,3}\\-\\d{1,2}\\-\\d{1,2}quot;);
QRegularExpressionValidator *numberValidator = new QRegularExpressionValidator (numberRegex);
code for adding a mask and the validator itself for QLineEdit:
ui->lineEdit_4->setValidator(numberValidator);
ui->lineEdit_4->setInputMask("+7(000)000-00-000");
Everything works correctly, the number is entered in the correct form, but there is a problem: When writing a number, I can erase by pressing (backspace), but after I enter the last character, I can't erase anymore.
UPD:If I make a mask with an additional "0" at the end, then everything is erased, but it no longer fits the mask I need. TOTAL: if the mask and the validator "coincide", then at the end of writing it is impossible to erase
UPD2: if i click ALT+Shift last 2 symbols will be erased anyway
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论