Hi all!
I'm making a gui app which contains some lineedits to let the user introduce some information. For that I set some QRegExp and QValidator and it works fine except for 2 cases that I hope that you can help me
Case 1: a Lineedit that has to accept 3 letters which are ABC and max 5 numbers. For example... valid inputs: ABC12345 / ABC00000 / ABC1234 / ABC89865.... invalid inputs: ABC 1234 / AAA12345 / AB / ABC / A / ...
I have this code but it acepts too A / AA / ... and I want to force the user to write ABC and at least 2 numbers
lineedit_case1->setValidator(validator3);
QRegExp rx3("[A][B][C]\\d{5}");
QValidator *validator3 = new QRegExpValidator(rx3, this);
lineedit_case1->setValidator(validator3);
To copy to clipboard, switch view to plain text mode
Another thing is that I want it to acept the user to put abc12345 BUT the line edit shows ABC12345. I mean: If the user write letters with caps lock or not, the line edits should always shows the text in uppercase. And with my code it only accepts that the user has the caps lock on.
Case 2: A line edit which accept a normal string BUT as the last example, if the user write it in downcase, the line edit has to show it in uppercase. I tried with a inputmask but it still shows in down case, the cursor its extrange and it doent acept spaces
lineedit_case2->setInputMask(">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
lineedit_case2->setInputMask(">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
To copy to clipboard, switch view to plain text mode
I tried it with:
connect(lineedit_Num1,
SIGNAL(textChanged
(QString)),
SLOT(toUpper(QString)));
{
QLineEdit *le
= qobject_cast<QLineEdit
*>
(sender
());
if (!le)
return;
le->setText(text.toUpper()); // found this looking on internet but not sure about how it works
lineedit_Num1->setText(text.toUpper()); //trying if that works
}
connect(lineedit_Num1, SIGNAL(textChanged(QString)), SLOT(toUpper(QString)));
void Test::toUpper(QString text)
{
QLineEdit *le = qobject_cast<QLineEdit *>(sender());
if (!le)
return;
le->setText(text.toUpper()); // found this looking on internet but not sure about how it works
lineedit_Num1->setText(text.toUpper()); //trying if that works
}
To copy to clipboard, switch view to plain text mode
Thank you so much
Bookmarks