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. Preventing cursor moving after text property is set
Qt 6.11 is out! See what's new in the release blog

Preventing cursor moving after text property is set

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.4k 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.
  • S Offline
    S Offline
    skinkie
    wrote on last edited by
    #1

    On several places the question has been raised how to overcome the moving of a cursor to the end of the widget each time the text property is updated. This happens when a QLineEdit widget is connected via a QDataWidgetMapper to a model, and this model emits datachanged.

    The hints on multiple places is: store the cursor position. But I think this can only be achieved by a hack, which basically attaches the affected widgets under the model to the model. Before the data changed store the QTextCursor and after the signal, apply it again.

    The more practical question is: is there a way to do it in a less hacky way. Or prevent the moment from a programmatic input at all?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Since you mention QDataWidgetMapper, you can use a custom property that will receive the data change and handle the cursor position the way you want it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ S 2 Replies Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        Since you mention QDataWidgetMapper, you can use a custom property that will receive the data change and handle the cursor position the way you want it.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @SGaist said in Preventing cursor moving after text property is set:

        you can use a custom property that will receive the data change and handle the cursor position the way you want it.

        That's sneaky/clever!

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Since you mention QDataWidgetMapper, you can use a custom property that will receive the data change and handle the cursor position the way you want it.

          S Offline
          S Offline
          skinkie
          wrote on last edited by
          #4

          @SGaist this in indeed a very cool trick that works even better than I thought.

          I have added a custom property text2 that was set as the user property. This also means that I do not have to change the QDataWidgetMapper addMapping function, since that one requests the user property to begin with.

          Thank you very much for this sneaky/clever trick as @JonB points out :-)

          1 Reply Last reply
          0
          • SGaistS SGaist has marked this topic as solved on

          • Login

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