QTextEdit needs to be tuned in such way that it should put space after each 2 symbols and it should check if these symbols are in sets from 0 to 9 or from A to F. for example I enter a2324Fcd and get A2 32 4F CD
Asked
Active
Viewed 2,974 times
2 Answers
1
You can implement this behaviour manually:
void MainWindow::on_textEdit_textChanged() {
QString text = ui->textEdit->toPlainText().toUpper();
text.replace(QRegExp("[^A-F]"), "");
QStringList tokens;
for(int i = 0; i < text.length(); i += 2) {
tokens << text.mid(i, 2);
}
ui->textEdit->blockSignals(true);
ui->textEdit->setText(tokens.join(" "));
ui->textEdit->moveCursor(QTextCursor::EndOfBlock);
ui->textEdit->blockSignals(false);
}
Note that this implementation makes difficult to edit text in the middle of the line. If it's a problem, more complicated implementation required.

Pavel Strakhov
- 39,123
- 5
- 88
- 127
-
You mean QRegExp("[^0-F]") from 0 to 9 or from A to F – WierdGreenCat May 24 '19 at 06:49
0
You can do the following:
QLineEdit le;
le.setInputMask("HH HH HH"); // Extend if more characters needed.
le.show();
BTW, QTextEdit
does not seem to support input masks.

vahancho
- 20,808
- 3
- 47
- 55
-
1Input mask it is like an abstract concept. And i need enter a hexs without knowing they length. – Mouse Feb 06 '14 at 13:47