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. Correct way to select/replace all text of a TextField if it gains focus?
Forum Updated to NodeBB v4.3 + New Features

Correct way to select/replace all text of a TextField if it gains focus?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 3.0k 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.
  • R Offline
    R Offline
    robro
    wrote on last edited by
    #1

    Hello,

    I have a TextField in QML and I would like to be able to immediately replace the old text with a new text by entering the field and typing without deleting the old text manually.

    Therefore, I would like to automatically select all old text whenever the field has the focus.
    Also, it would be good, that if no new text is typed the old text stays.
    How do I do that?

    Thank you very much :-)

    J.HilkJ 1 Reply Last reply
    0
    • R robro

      Hello,

      I have a TextField in QML and I would like to be able to immediately replace the old text with a new text by entering the field and typing without deleting the old text manually.

      Therefore, I would like to automatically select all old text whenever the field has the focus.
      Also, it would be good, that if no new text is typed the old text stays.
      How do I do that?

      Thank you very much :-)

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @robro

      the selectAll methos should be all you need:
      http://doc.qt.io/qt-5/qml-qtquick-controls-textfield.html#selectAll-method

      possible usage:

      TextField{
      ....
            onFocusChanged:{
                 if(focus)
                     selectAll()
            }
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • R Offline
        R Offline
        robro
        wrote on last edited by
        #3

        Thank you! :-)

        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