-1

我是 Qt 的新手。

只是想问我应该使用什么来在 Qt 中创建一个将采用单个整数值的编辑框?

谢谢。

4

1 回答 1

2

最简单的解决方案:

QValidator *validator = new QIntValidator(0, 9, this);
QLineEdit *edit = new QLineEdit(this);

// the edit lineedit will only accept integers between 0 and 9
edit->setValidator(validator);

您可以在此处阅读有关 Validator 的更多信息:http: //doc.qt.io/qt-5/qintvalidator.html以及有关 QLineEdit 的更多信息:http: //doc.qt.io/qt-4.8/qlineedit.html#details

于 2016-01-07T13:28:48.197 回答