Before 5.12:
Handle the textChanged
signal of QLineEdit
.
connect(lineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(lineEditTextCahnged(const QString&)));
Now in the slot, look for clip board text.
If both are same, then it is a kind of paste action.
Then validate your length.
Soem psudo-code below.
void yourclass::lineEditTextCahnged(const QString& text)
{
QClipboard *pBoard = QApplication::clipboard();
QString clipStr = pBoard->text();
if (clipStr == text)
{
//THEN IT IS SOME PASTE ACTION.
//HANDLE YOUR LENGTH VALIDATION.
}
}
Version 5.12:
Handle void QLineEdit::inputRejected()
signal
The documentation says
Note: This signal will still be emitted in a case where part of the
text is accepted but not all of it is. For example, if there is a
maximum length set and the clipboard text is longer than the maximum
length when it is pasted.
http://doc.qt.io/qt-5/qlineedit.html#inputRejected