user987013
user987013

Reputation: 243

how to set validator with QDoubleValidator? (QValidator)

I now have a class called EditBox which inherit from Qwidget and QTextEdit

And I'm trying to set a validator to this text edit box....

EditBox manbox;

How do I set up a validator to 0~100? with 2 decimal point?

I've tried

QDoubleValidator *testQD = new QDoubleValidator(manbox);
testQD->setRange(0.00,100.00,2);

QLineEdit *sb1 = new QLineEdit( manbox );
sb1->setValidator(testQD);

but seems not working. Any where went wrong?

Or please guide me somewhere i can find full tutorial for this one. Thanks!

Upvotes: 0

Views: 1702

Answers (1)

alexisdm
alexisdm

Reputation: 29886

You can't set a validator for a QTextEdit, it only works for QLineEdit (and input widgets containing a QLineEdit like QSpinBox, QComboBox...).

If you only need one line, and restrict the content to a number, you could as well replace the QTextEdit in your class EditBox by a QLineEdit or a QDoubleSpinBox.

Upvotes: 3

Related Questions