How to maximum length and Input validator for qtextedit



  • Is it possible to set maximum Input length and validator for qtextedit, I know all these properties available in qlineedit, but Im my application I need these kind of properties in textedit..


  • Moderators

    for QTextEdit maximum input length see "this":http://qt-project.org/faq/answer/how_can_i_get_set_the_max_length_of_a_qtextedit.

    For the QValidator you would need to handle it yourself. Meaning calling QValidator::validate() and QValidator::fixup() yourself on text changes. And doing the validation yourself with the help of QValidator concept.



  • I already read that example lots of time, but I couldn't understand concept of that example, eventhough I already implemented my own textedit named as MyTextEdit and create a placeholder property.. pls give your example or tell what you can get from that example..


  • Moderators

    i don't know how this example could be any simpler for the task you want. Also the text explains it also very well, there is nothing to know more...

    Understand the concepts of QKeyEvents and QTextEdit API is the only requirement for this example IMHO.



  • Thanks raven,

    Now I found solution from your example. But Still I struggling in validation of Inputs. I already refer QRegExp validator, but how to set that validator for Qtextedit..



  • Hi,

    bq. but how to set that validator for Qtextedit..

    you were told by raven-worx, you must call explicitly QValidator::validate ( QString & input, int & pos ) ... but what you really need is a custom implemantation of a QValidator, so subclass it and us it in tandem with the textedit ... you cannot set a validator for a textedit, and you dont really need it: for line edit setting a validator by setValidator only enable a mechanism by which the focus input text is automatically (transparent to the programmer) passed to the validator, in rest everything being executedin the same sequence

    ... connect textedit textChanged () signal with a slot where the text is passed to the validator, get the validate() state and accordingly leave or reset the focus to the textedit ...

    hope it enlighten a little!

    Cheers!


Log in to reply
 

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