1.QLineEdit设置光标位置
ui->lineEdit->setCursorPosition(0);
2.QLineEdit设置只读
ui->lineEdit->setReadOnly(true);
3.QLineEdit设置限制输入的最小值、最大值
ui->lineEdit->setValidator(new QIntValidator(1, 59, this));
4.QLineEdit限制某些特殊符号在lineEdit中的输入
QRegExp rx = QRegExp("[^\\\\/:;*?\"<>|^]*");
QRegExpValidator* validator = new QRegExpValidator(rx);
ui->lineEdit->setValidator(validator);
5.QLineEdit设置占位字符
ui->lineEdit->setPlaceholderText("请输入账号");
6.QLineEdit设置一键清除图标
ui->lineEdit->setClearButtonEnabled(true);
7.QLineEdit设置输入图标
QAction *searchActionID = new QAction(ui->lineEdit_ID);
searchActionID->setIcon(QIcon(":/images/userIdLogo.png"));
ui->lineEdit_ID->addAction(searchActionID,QLineEdit::LeadingPosition );
8.QLineEdit设置密码框文章来源:https://www.toymoban.com/news/detail-708727.html
ui->lineEdit_pwd->setEchoMode(QLineEdit::Password); // 密码输入框
参考效果图:文章来源地址https://www.toymoban.com/news/detail-708727.html
到了这里,关于Qt:QLineEdit的使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!