PDA

View Full Version : Problems with QLineEdit



RSX
24th June 2009, 14:33
The first problem is that QLineEdit (or maybe QLocale) does auto spaces.


flags = 1048576;
QLocale convert;
ui->lineEditFlags->setText(convert.toString(flags));


And the result I get is:

1 048 576
... with white spaces =/

The second problem is that:


QValidator *validator = new QIntValidator(this);
ui->lineEditFlags->setValidator(validator);


It works fine until my program sets text to something like 1 048 576 (something that has whitespace). Then I can enter any character I want =/

Any way to fix these?

Lykurg
24th June 2009, 14:41
Don't use QLocale, simply
ui->lineEditFlags->setText(QString::number(flags));is enough.

Lykurg
24th June 2009, 14:46
The second problem is that:


QValidator *validator = new QIntValidator(this);
ui->lineEditFlags->setValidator(validator);


It works fine until my program sets text to something like 1 048 576 (something that has whitespace). Then I can enter any character I want =/

you can also set a QLineEdit::inputMask.

RSX
24th June 2009, 14:50
Thanks that worked.

petrov_sasha
28th September 2009, 17:02
Hi, I have the same problem:

I using QLineEdit and QRegExpValidator:

1) These code is working correctly
@lneLne1.setText("QWERTY1")
@lneLne1.setValidator(Qt::RegExpValidator.new(Qt:: RegExp.new('[\x0410- \x044F]*'), @lneLne1)). We set invalid string "QWERTY1" in lneLne1 and set after validator for russian character. Now we can't input(manually) any character because text in @lneLne1 is invalid.

But if we add string @lneLne1.setText("qWERTY") in the end, i.e. we have code:
@lneLne1.setText("QWERTY1")
@lneLne1.setValidator(Qt::RegExpValidator.new(Qt:: RegExp.new('[\x0410-\x044F]*'), @lneLne1))
@lneLne1.setText("qWERTY")
then validator is disabled!!!:(
(I can input any symbol in field). And i can't enable it again.

PS: I coding in RubyQt