Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75756

QLineEdit::setSelection does not allow setting the cursor position

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 5.12.2
    • None

    Description

      This is probably a corner-case, but I think it's missing functionality or a (minor) bug:

      When setting a QLineEdit's selection using QLineEdit::setSelection, it's not possible to set the position of the cursor. QWidgetControl::setSelection always sets the cursor to the end of the selection.

      My use-case for finding this is that I cache the state of a QLineEdit (text, selection and cursor position) and restore it later. Now, one can set a selection by holding shift and pressing the left arrow key, which results in a selection with the cursor being at the beginning of the selection and not at the end.

      Currently, there seems to be no way to reconstruct such a selection, as setSelection always positions the cursor at the end, and setCursorPosition does set a defined position, but discards the selection.

      When one enters some text after the restoring, it doesn't matter as the selection is replaced by the input no matter if the cursor is at the beginning or the end of the selection. But if one sets the selection programmatically and the cursor was at the beginning and the user presses an arrow key, the cursor jumps to end of the selection, which is at least unexpected.

      Surely no release blocker, but probably something you want to change

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            l3u Tobias Leupold
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes