【发布时间】:2021-10-21 14:47:44
【问题描述】:
是否可以限制QInputDialog::getText 的长度?例如,我想直接在 InputDialog 中将用户输入的长度限制为 10 个字符。不幸的是,没有像QInputDialog::setMaximum 这样的函数。
这是我当前的代码:
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();
}
...
【问题讨论】:
-
QInputDialog 没有那个功能;不过,您可能会继承并实现您想要的功能。
标签: c++ qt qt5 qinputdialog