PDA

View Full Version : setValidator



:db:sStrong
13th April 2006, 10:33
hello guys,

i have a question about whether there is a way to use setValidator for the qtable. I have 3 cols and one of them is editable but i want to restrict the users to type for example integers between 2 and 16000. can someone tell me if it is possible??. I use qt3 and am a beginner on this area.

thanx in advance.

jacek
13th April 2006, 14:16
You might try to reimplement this:
QWidget * QTableItem::createEditor () const [virtual]
This virtual function creates an editor which the user can interact with to edit the cell's contents. The default implementation creates a QLineEdit.
If the function returns 0, the cell is read-only.
The returned widget should preferably be invisible, ideally with QTable::viewport() as parent.
If you reimplement this function you'll almost certainly need to reimplement setContentFromEditor(), and may need to reimplement sizeHint()
or QTable::createEditor().

:db:sStrong
15th May 2006, 11:04
You might try to reimplement this:
or QTable::createEditor().

yes it works like this en thnx for the information.. i have now another problem with the validate values.. i want to type only the integers bigger than 2 and smaller than 16000. i have this line code:---


QRegExp RegExp( "^[3-9]\\d{0,4}$" );

but this is ofcourse not good because i validate the values between 3 to 9 and with 4 zeros.. is there a way to just validate this 2> and <16000??

thnx in advance..

jacek
15th May 2006, 11:09
Try:
"^1[0-5]\\d{3}|[1-9]\\d\\d?|[2-9]$"

:db:sStrong
15th May 2006, 11:23
Try:
"^1[0-5]\\d{3}|[1-9]\\d\\d?|[2-9]$"

no it does not work, i shouldnt type 1, 2 all integers bigger dan 2 and smaller than 16000 :(

its a bit tricky cuz if i dont want to type 1 then i am not able to type 11 and 16000..

jacek
15th May 2006, 12:12
Does this work?
"^(?:1[0-5]\\d{3}|[1-9]\\d{1,3}|[3-9])$"

:db:sStrong
15th May 2006, 12:22
Does this work?
"^(?:1[0-5]\\d{3}|[1-9]\\d{1,3}|[3-9])$"

this works partially.. the integers < 16000 works fine but i am still able to type 1 and 2.. this part doent work >2(bigger than 2 means no 0, 1 and 2)

jacek
15th May 2006, 13:01
but i am still able to type 1 and 2.. this part doent work >2(bigger than 2 means no 0, 1 and 2)
How do you expect to type in 11111 if you can't type in 1?

:db:sStrong
15th May 2006, 13:19
How do you expect to type in 11111 if you can't type in 1?

yep thats why it is abit dumb if am not able to type 1 then i cant type 11111 either but i have to find way to dont allow 1 an 2 but do allow i.e 11, 11111, 12, 12222...

jacek
15th May 2006, 14:18
yep thats why it is abit dumb if am not able to type 1 then i cant type 11111 either but i have to find way to dont allow 1 an 2 but do allow i.e 11, 11111, 12, 12222...
It should work --- according to kregexpeditor the above regexp doesn't match "0", "1" and "2".

You could use QSpinBox instead of QLineEdit.

fullmetalcoder
15th May 2006, 16:25
Couldn't you find a way to access the string, convert it to integer and check if it match your needs?
I guess some signals or event allows you to do that...

:db:sStrong
16th May 2006, 09:59
Couldn't you find a way to access the string, convert it to integer and check if it match your needs?
I guess some signals or event allows you to do that...

No i couldnt find a way to do such but i dont think so i have to convert string to integers but i am going search in qt documentation ...

thnxx