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. [Solved] TextInput overwriteMode
QtWS25 Last Chance

[Solved] TextInput overwriteMode

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.1k Views
  • 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.
  • E Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    Is there something like the QTextEdit overwriteMode ("overwriteMode-prop":http://qt-project.org/doc/qt-4.8/qtextedit.html#overwriteMode-prop) property for the Qml TextInput / TextEdit control?

    I couldn't find anything similar in the documentation :(

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rferrazz
      wrote on last edited by
      #2

      I think that isn't anything similar but you can do a simple hack to get the insert behaviour:

      @TextInput{
      id: input
      text: "ciao"
      onTextChanged: {
      var cursor = cursorPosition;
      text = text.substring(0, cursorPosition)+text.substring(cursorPosition+1, text.length);
      cursorPosition = cursor;
      }
      }@

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ephe
        wrote on last edited by
        #3

        Thank you! That's working fine.

        But I still wonder why there is no overwrite mode property in the TextInput control.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          I'd recommend adding a suggestion via http://bugreports.qt-project.org -- that way it has a better change of being looked into further and perhaps added in a future release.

          Regards,
          Michael

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ephe
            wrote on last edited by
            #5

            Thank you for the suggestion!
            "QTBUG-26513":https://bugreports.qt-project.org/browse/QTBUG-26513

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ephe
              wrote on last edited by
              #6

              I would also like the cursor to be different, depending on which mode is set.
              So I was thinking about selecting the characters to overwrite them:

              @
              TextInput
              {
              id: input
              text: "ciao"
              font.pixelSize: 20
              onTextChanged:
              {
              select(cursorPosition, cursorPosition+1);
              }
              }
              @

              This is working quite nice. But I don't know how to select the first character.
              I tried this:
              @
              Component.onCompleted: select(0, 1)
              @
              The character was selected, but I couldn't enter anything anymore. Also the left/right keys were not working.

              The other problem are the left/right buttons. I would need to set the selection when they are pressed, too.
              I tried this:
              @
              Keys.onPressed:
              {
              if(event.key == Qt.Key_Right)
              {
              select(cursorPosition, cursorPosition+1);
              }
              }
              @
              When the cursorPosition is 0 and I press the right arrow key, the cursor is on the second position (before the 'a'). When I press the right arrow key again, the cursor is behind the 'o' but nothing is selected

              I also tried to set the cursorDelegate, but the Rectangle is shown on top of the text.

              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