![]() |
Re: Need assistance from QT programmer
Hi again guys.
I need some help with validating user input and then do actions based on if the input is valid or not. So far I'm good with validating the input, the validator allows me only to input correctly formatted stuff. What it doesn't check is if the input length is enough. What I don't know is how to know later if the input was long enough or not. Here's what I do when program launches (I create the validator and set it to line edits): Code:
Code:
void MainWindow::on_line_edit_font1_editingFinished() |
Re: Need assistance from QT programmer
Quote:
Code:
if (ui->line_edit_font1->text().length() == 7) { I don't know how this qtvalidator work, but isn't that enough to prevent the short text? regards Nicolai |
Re: Need assistance from QT programmer
Quote:
What I want to achieve is that when user has typed in less than seven digits and he jumps to next box, it would revert the box value back to what it was before user started to type the stuff in the box. That way I could prevent situation where the box has less than seven digits in it. |
Re: Need assistance from QT programmer
Quote:
Quote:
Code:
QRegExp regexer("^\\#[0-9a-fA-F]{6,6}$"); (.. your characters ..) $ = until the end of the string Also, you might consider this: Code:
ui->line_edit_font1->setValidator(new QRegExpValidator(regexer, ui->line_edit_font1); Edit: this way, you don't have to make "actualvalidator". |
Re: Need assistance from QT programmer
Here's a screenshot of situation I wan't to avoid:
http://i4.aijaa.com/b/00298/6799969.png |
Re: Need assistance from QT programmer
Quote:
So maybe I need to do something with the validator? Tell validator to fill in the previous value if user didn't fill in all required digits? How? |
Re: Need assistance from QT programmer
Quote:
Quote:
|
Re: Need assistance from QT programmer
Maybe you can use void QLineEdit::editingFinished () signal.
This signal is emitted when the Return or Enter key is pressed or the line edit loses focus. Note that if there is a validator() or inputMask() set on the line edit and enter/return is pressed, the editingFinished() signal will only be emitted if the input follows the inputMask() and the validator() returns QValidator::Acceptable. The input is valid if the signal is emitted. |
Re: Need assistance from QT programmer
Quote:
|
Re: Need assistance from QT programmer
Is the behavrio different, if you use setInputMask instead
of a validator? http://doc.trolltech.com/4.7/qlineed...inputMask-prop ui->line_edit_font1->setInputMask("\#NNNNNN"); regards Nicolai |
All times are GMT. The time now is 23:14. |
vBulletin® Version 3.8.8