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

Material TextField / TextArea: cursorVisible ignores readOnly state

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.0 RC
    • 5.8.0
    • Quick: Controls 2
    • None
    • QtQuick 2 Material
      Qt 5.8
    • e1ae67cb2b9daa9bbbc9f87c8af03f3810022774

    Description

      Scenario:

      Using a TextField / TextArea from the QtQuick.Controls.Material style and controlling the readOnly flag manually:

      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          MouseArea { /* Helper to steal focus from TextField */
              anchors.fill: parent
              onClicked: focus = true;
          }
          TextField {
              text: "ChangeMe"
              readOnly: true
              onPressAndHold: {
                  readOnly = false
                  selectAll()
                  forceActiveFocus()
              }
              onEditingFinished: {
                  readOnly = true
              }
          }
      }
      

      Such that:

      • On press-and-hold editing is possible.
      • On click, field has active focus (no cursor should be visible)

      On first click to focus, no cursor is visible (as expected).
      But after the press-and-hold action, losing focus, and regaining focus again, the cursor is visible (while readOnly is true).

      This is a bug only persistent in the Material style for the TextField and TextArea.

      A possible fix is to take the readonly state (&& !control.readOnly) into account for the cursorDelegate its visible property:

          cursorDelegate: Rectangle {
          ...
              visible: control.activeFocus && control.selectionStart === control.selectionEnd
          ...
          }
      

      to

          cursorDelegate: Rectangle {
          ...
              visible: control.activeFocus && !control.readOnly && control.selectionStart === control.selectionEnd
          ...
          }
      

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            bartel Bartel Eerdekens
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes