Is there any kind of validator or maximum length that I can assign to QTextEdit control? I cannot use QLineEdit, because I need a multi-line entry widget...
Qt 3.20
Is there any kind of validator or maximum length that I can assign to QTextEdit control? I cannot use QLineEdit, because I need a multi-line entry widget...
Qt 3.20
You can always install an event filter choosing not to pass on additional characters if the length reaches your limit. Just make sure that you pass on movements (up, down, left, right, pgup, pgdn, home, end) and deletions (delete, backspace).
Connect the signal QTextEdit::textChanged () to a slot wherein you can limit the input to your needs.
The idea was to have something like this in the slot handling the textChanged() signal :
Qt Code:
textedit.setPlainText(rightLengthText);To copy to clipboard, switch view to plain text mode
But this could lead to a recursivity issue with the textChanged() signal except if QObject::blockSignals ( bool block ) is enough for not triggerering the potentially recursive textChanged signal.
Instead of controlling the length of the input we limit the output length.
Last edited by toutarrive; 10th March 2010 at 14:07.
void on_edit_textChanged()
{
if (edit.text().length() > MAX_LENGTH) {
edit->textCursor().deletePreviousChar();
}
}
That also wont work. Just guess you are inserting a long text by CTRL+C or drop it in. For that you have to replace the if by while and that is nasty.
..or you have to select the previous characters and delete them. But still, that is not nice. Best would be to disallow the copying if it is to long. So still the solution of johan is the only "valid" one.
Bookmarks