Connect the signal QTextEdit::textChanged () to a slot wherein you can limit the input to your needs.
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