Unsolved How do i Create a Custom Validator?
-
hi i want to create an int validator that only allows 0 - 255 numbers. but i don't know the syntax of creating a custom int validator.
-
@nullbuil7
Use aQIntValidator
! I know you don't like this from your other thread. I suppose you could derive fromQIntValidator
and overridevalidate()
to returnInvalid
instead ofIntermediate
if the third digit puts it over 255. You'd have to try it out and see how it behaves.But why aren't you using a QSpinBox for your widget, that has a minimum and a maximum, it's a dedicated widget for what you want? You seem to want to reinvent the wheel in your situation?
-
I'm sorry I'm just new at this and i was don't know enough qt and c++ yet. sorry for spamming I'll try QSpinBox
-
@nullbuil7
If the spin box does not suit you, I have edited to suggest above how you might subclassQIntValidator
to alter the default 3-digit behaviour to what I think you are looking for. -
how do i get around this?