Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Validator for TextArea/TextEdit
Forum Updated to NodeBB v4.3 + New Features

Validator for TextArea/TextEdit

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 616 Views 2 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.
  • K Offline
    K Offline
    Kenz Dale
    wrote on last edited by Kenz Dale
    #1

    I am writing a hex editor and would like a validator on a QML TextEdit/TextArea component in order to disallow any non-hex characters. Validators seem to be supported in the single-line components TextInput/TextField, but those are sadly not appropriate for an editor.

    Can this be done?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi

      my first feeling in this case would be monitoring any text change, remove any prohibited character if any (would be located just before the current cursor position), then reposition the cursor if necessary.

      something like this

      TextEdit // Or TextArea
      {
          id: textEdit
          anchors, height or width at your convenience
      
          onTextChanged:
          {
              const oldCursorPosition = cursorPosition
              text = textParserFunction (text)
              cursorPosition = oldCursorPosition - 1
          }
      }
      
      K 1 Reply Last reply
      0
      • ? A Former User

        Hi

        my first feeling in this case would be monitoring any text change, remove any prohibited character if any (would be located just before the current cursor position), then reposition the cursor if necessary.

        something like this

        TextEdit // Or TextArea
        {
            id: textEdit
            anchors, height or width at your convenience
        
            onTextChanged:
            {
                const oldCursorPosition = cursorPosition
                text = textParserFunction (text)
                cursorPosition = oldCursorPosition - 1
            }
        }
        
        K Offline
        K Offline
        Kenz Dale
        wrote on last edited by
        #3

        @ankou29666 That's my thinking as well, although IMHO that's an ugly hack to work around the lack of a validator. Maybe that's the best we can do, though?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          I don't really like this either but this is the same kind of bullshit I use to prevent the cursor to be freely moving (I mean forcing the cursor back behind the last valid character) when using an input mask over a TextEdit

          K 1 Reply Last reply
          0
          • ? A Former User

            I don't really like this either but this is the same kind of bullshit I use to prevent the cursor to be freely moving (I mean forcing the cursor back behind the last valid character) when using an input mask over a TextEdit

            K Offline
            K Offline
            Kenz Dale
            wrote on last edited by
            #5

            @ankou29666 I'm guessing you have to have some guards on text so that the self-modification of text doesn't trigger an infinite loop of onTextChange() events?

            ? 1 Reply Last reply
            0
            • K Kenz Dale

              @ankou29666 I'm guessing you have to have some guards on text so that the self-modification of text doesn't trigger an infinite loop of onTextChange() events?

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @Kenz-Dale In normal world of Qt, if you set a property which is already set to the not so new value, the propertyChanged signal is not emitted.

              fcarneyF 1 Reply Last reply
              0
              • ? A Former User

                @Kenz-Dale In normal world of Qt, if you set a property which is already set to the not so new value, the propertyChanged signal is not emitted.

                fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by fcarney
                #7

                @ankou29666 What if you capture key presses and only let what you want get through to the TextEdit? event.accepted = true only for keys you want to be pressed.

                Edit: I mean false. Also, I think I meant to reply to @Kenz-Dale

                C++ is a perfectly valid school of magic.

                ? 1 Reply Last reply
                0
                • fcarneyF fcarney

                  @ankou29666 What if you capture key presses and only let what you want get through to the TextEdit? event.accepted = true only for keys you want to be pressed.

                  Edit: I mean false. Also, I think I meant to reply to @Kenz-Dale

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  @fcarney Interesting idea

                  1 Reply Last reply
                  0
                  • B barbicels referenced this topic

                  • Login

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