Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QDoubleValidator is not working?

I'm trying to apply validator in a line edit box in Qt 4.2 and it is not working:

 QDoubleValidator *haha= new QDoubleValidator(this);
 haha->setBottom(0.00);
 haha->setDecimals(2);
 haha->setTop(100.00); 
 get_line_edit()->setValidator(haha);

or

 QDoubleValidator *haha= new QDoubleValidator(0.00,100.00,2,this);

Neither way, I can still enter what ever value I want.

But if I switch to QIntValidator, it works!

So I went onto Google and did a bit search, and many people used to having the same issue. Is it a bug? or there should be some other set up I should do?

like image 639
user987013 Avatar asked Apr 12 '12 07:04

user987013


2 Answers

Just tripped over this one. Try setting the QDoubleValidator notation to:

doubleValidator->setNotation(QDoubleValidator::StandardNotation);
like image 62
soulia Avatar answered Sep 20 '22 14:09

soulia


The validator documentation says that it returns "Intermediate" from "validate" when the input is an arbitrary double but out of range.

You need to distinguish intermediate input and the final input the user wants to submit by use of a line edit control (e.g. by emitting the "returnPressed" signal). If the user typed "10000" that is still a valid intermediate input for a number between 0 and 100 because the user can prefix this input with "0.".

like image 40
Johannes Schaub - litb Avatar answered Sep 20 '22 14:09

Johannes Schaub - litb