Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to maximum length and Input validator for qtextedit
Forum Updated to NodeBB v4.3 + New Features

How to maximum length and Input validator for qtextedit

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guru
    wrote on last edited by
    #1

    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..

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        guru
        wrote on last edited by
        #3

        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..

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guru
            wrote on last edited by
            #5

            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..

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NicuPopescu
              wrote on last edited by
              #6

              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!

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved