[Solved] Validating when a button is pressed



  • I just tried to validate a QLineEdit.
    I have set a QValidator which checks if the entered text is between 0 and 100. Now only values between 0 and 100 can be entered, which is fine.
    But is it also possible to let the user enter everything and check afterwards if it is a valid input?

    I know that the usability is better if the user cannot even enter wrong values, but still sometimes I would like to validate after the focus moved to the next element or if "OK" was pressed.



  • Let me explain you how to act in such cases (before posting a question)

    So you have a QValidator object that is ok for you. But it works with QLineEdit in some specific way you want to avoid. That means you shouldnt call setValidator.

    Next. What a QValidator does? It (omg) validates!! That means that the job of this class is to check if string is ok. And probably, it has some publick inteface for that. So let's have a look a the class reference ... and .... voila, it has validate method, which you can use anywhere you want.

    What's the moral of all that? Use qt reference and your mind. Both are awesome.



  • [quote author="saho" date="1320674768"]
    But is it also possible to let the user enter everything and check afterwards if it is a valid input?
    [/quote]

    Connect a slot to the focus signals (which one you are interested in) and call the validator's validate method there, without having to tying the validator to the line editor.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.