@@ -536,10 +536,8 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias,
536536 if (m_lineEdit == NULL ) {// 创建DLineEdit,设定显示规则。
537537 m_lineEdit = new DLineEdit (this );
538538 // 输入字符格式与文管保持一致
539- connect (m_lineEdit, &DLineEdit::textChanged,[=](){
540- QString name = " (^\\ s+|[/\\\\ :*\" '?<>|\r\n\t ])" ;
539+ connect (m_lineEdit, &DLineEdit::textChanged, [=](){
541540 QString text = m_lineEdit->text ();
542- m_lineEdit->setText (text.remove (QRegularExpression (name)));
543541 if (m_nOkBtnIndex >= 0 ) { // 重命名输入文字为空时确认按钮不可点击,输入文字后恢复
544542 if (text.isNull ()||text.isEmpty ()){
545543 getButton (m_nOkBtnIndex)->setEnabled (false );
@@ -548,6 +546,22 @@ int RenameDialog::showDialog(const QString &strReName, const QString &strAlias,
548546 }
549547 }
550548 });
549+
550+ // 失去焦点时,检查并清理非法字符
551+ connect (m_lineEdit->lineEdit (), &QLineEdit::editingFinished, [=](){
552+ QString name = " (^\\ s+|[/\\\\ :*\" '?<>|\r\n\t ])" ;
553+ QRegularExpression regex (name);
554+ QLineEdit *lineEdit = m_lineEdit->lineEdit ();
555+ QString text = lineEdit->text ();
556+
557+ // 检查是否有非法字符
558+ if (regex.match (text).hasMatch () || text.startsWith (" " )) {
559+ QString cleanedText = text;
560+ cleanedText.remove (regex);
561+
562+ lineEdit->setText (cleanedText);
563+ }
564+ });
551565 }
552566 DLabel *strlabel = new DLabel;
553567 strlabel->setObjectName (" ContentLabel" );
0 commit comments