is it possible to restrict the length in a QInputDialog::getText
? For example, I want to restrict the length from the user input to 10 characters directly in the InputDialog. Unfortunately, there isn't a function like QInputDialog::setMaximum
.
Here's my current code:
QString input = QInputDialog::getText(this, tr("Find"), tr("Enter text:"), QLineEdit::Normal, "", nullptr, Qt::WindowFlags(), Qt::ImhDialableCharactersOnly);
if (input == "")
return;
else if (input.length() > 10)
{
QMessageBox::warning(this, tr("Invalid input", "Note #1"), tr("Input is too long."));
// This is this function name (calls itself again)
on_actionFind_triggered();
}
...
Very easy with a signal/slot mechanism and a signal blocker...
Another posibility would be to find
QLineEdit
child of the dialog using and then assign a certainQValidator
to it. I have not tested this but it should work as well. But then you would need to program the maximum length validator.