对QLineEdit进行输入控制

时间:2022-03-06 00:35:10
void Window::echoChanged(int index)
{
switch (index) {
case 0:
//默认,输入什么即显示什么
echoLineEdit->setEchoMode(QLineEdit::Normal);
break;
case 1:
//密码,一般是用小黑点覆盖你所输入的字符
echoLineEdit->setEchoMode(QLineEdit::Password);
break;
case 2:
//编辑时输入字符显示输入内容,否则用小黑点代替
echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
break;
case 3:
//任何输入都看不见(只是看不见,不是不能输入)
echoLineEdit->setEchoMode(QLineEdit::NoEcho);
}
}
void Window::validatorChanged(int index)
{
switch (index) {
case 0:
//无限制
validatorLineEdit->setValidator(0);
break;
case 1:
//只能输入整数
validatorLineEdit->setValidator(new QIntValidator(
validatorLineEdit));
break;
case 2:
//实例,只能输入-180到180之间的小数,小数点后最多两位(可用于限制经纬度等)
QDoubleValidator *pDfValidator = new QDoubleValidator(-180.0, 180.0 , 2, validatorLineEdit);
pDfValidator->setNotation(QDoubleValidator::StandardNotation);
validatorLineEdit->setValidator(pDfValidator);
}

validatorLineEdit->clear();
}

void Window::alignmentChanged(int index)
{
switch (index) {
case 0:
alignmentLineEdit->setAlignment(Qt::AlignLeft);
break;
case 1:
alignmentLineEdit->setAlignment(Qt::AlignCenter);
break;
case 2:
alignmentLineEdit->setAlignment(Qt::AlignRight);
}
}
void Window::inputMaskChanged(int index)
{
switch (index) {
case 0:
inputMaskLineEdit->setInputMask("");
break;
case 1:
inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
break;
case 2:
inputMaskLineEdit->setInputMask("0000-00-00");
inputMaskLineEdit->setText("00000000");
inputMaskLineEdit->setCursorPosition(0);
break;
case 3:
inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
}
}

void Window::accessChanged(int index)
{
switch (index) {
case 0:
accessLineEdit->setReadOnly(false);
break;
case 1:
accessLineEdit->setReadOnly(true);
}
}

对QLineEdit进行输入控制

相关文章