How about using QIntValidator?Originally Posted by :db:sStrong
Besides, you can do it with regular expressions as well, something like this should work:
Qt Code:
To copy to clipboard, switch view to plain text mode
How about using QIntValidator?Originally Posted by :db:sStrong
Besides, you can do it with regular expressions as well, something like this should work:
Qt Code:
To copy to clipboard, switch view to plain text mode
Originally Posted by wysota
this reg doesnt work i am not able to type anything![]()
Love::Peace
Why dont you use QIntValidator (as suggested by wysota) and set the range ?
Mithin
www.mithin.in
i am using now QIntValidator:Originally Posted by munna
Qt Code:
validator->setRange(3,16000); le->setValidator(validator); le->clear();To copy to clipboard, switch view to plain text mode
but i am still able to type 1 and 2 i want to have this: >2 and <=16000. the top is good but the bottom value is not good in above code.
Love::Peace
You can type "1" because to type "1000" you have to be able to type "1"Originally Posted by :db:sStrong
It's just not being accepted as a valid value, but you have to be able to type it in. I think that if the lineedit loses focus, the value will be corrected to a valid one. But maybe it'd be easier for you to use QSpinBox?
no i have to use qlineedit in order to clear. the users should only type >2 and <16000 i am going to use focus now lets see what happens..Originally Posted by wysota
Love::Peace
So tell me something. How do you intend to enter "1111" (which is a valid value) if you forbid to enter a "1"?
Here is my code, try it:
Qt Code:
#include <QApplication> #include <QIntValidator> #include <QLineEdit> #include <QDialog> #include <QVBoxLayout> public: }; int v = input.toInt(); } int main(int argc, char **argv){ QDialog dlg; layout->addWidget(le); layout->addWidget(other); dlg.setLayout(layout); le->setValidator(validator); dlg.show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
hi I have change ur code according to my situation because i dont use QLineEdit as a class i have qtable and just one COL is made QlineEdit, this is the code:Originally Posted by wysota
Qt Code:
{ QString input; int v = input.toInt(); if (le) { validator->fixup(input); le->setValidator(validator); } return le; }To copy to clipboard, switch view to plain text mode
the fixup doesnt work good because i am still able to write 1 and 2![]()
Love::Peace
Maybe you didn't notice -- I subclassed QIntValidator. The default implementation of fixup() does nothing so you have to subclass the validator and implement it.
oke i see i have also subclass QIntvalidator:Originally Posted by wysota
Qt Code:
public: }; int v = input.toInt(); } { le->setValidator(validator); return le; }To copy to clipboard, switch view to plain text mode
but still its not working, am i doing somthing wrong with subclassing??
Love::Peace
You are still creating an instance of QIntValidator instead of your subclass.Qt Code:
To copy to clipboard, switch view to plain text mode
:db:sStrong (23rd May 2006)
I think you need to use QSpinBox.
If you are very particular about QLineEdit then try
Qt Code:
{ lineEdit->setFrame(false); //use connect here. return lineEdit; }To copy to clipboard, switch view to plain text mode
Mithin
www.mithin.in
Bookmarks