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

TextArea is overlaped by virtual keyboard (keyboardRectangle is corrupted after 'copy&paste' insertion)

    XMLWordPrintable

Details

    • Android, iOS/tvOS/watchOS

    Description

      The smallest but reproducible example is attached but I guess that everything boils down to ScrollView/TextArea size manipulations by RowLayout: 

      import QtQml 2.15
      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      import QtQuick.Layouts 1.15
      
      ApplicationWindow {
          title: qsTr("qtbug1-demo")
          visible: true
          Connections {
              target: Qt.inputMethod
              function onKeyboardRectangleChanged() {
                  var newRect = Qt.inputMethod.keyboardRectangle;
                  console.log(
                      "Qt.inputMethod::onKeyboardRectangleChanged" +
                      " x: " + newRect.x +
                      " y: " + newRect.y +
                      " width: " + newRect.width +
                      " height: " + newRect.height
                  );
              }
          }
          ColumnLayout {
              id: layout
              anchors.fill: parent
              ListView {
                  id: listView
                  Layout.fillWidth: true
                  Layout.fillHeight: true
                  model: 1000
                  delegate: Label {
                      text: index
                  }
                  onMovementStarted: {
                      if (!activeFocus) {
                          focus = true;
                      }
                  }
              }
              Pane {
                  id: inputPane
                  Layout.fillWidth: true
                  RowLayout {
                      id: rowLayout
                      width: parent.width
                      spacing: 2
                      ScrollView {
                          id: scrollView
                          Layout.fillWidth: true
                          Layout.maximumHeight: Screen.desktopAvailableHeight / 4
                          Layout.preferredHeight: textArea.implicitHeight
                          Layout.alignment: Qt.AlignVCenter
                          ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
                          ScrollBar.horizontal.interactive: false
                          onHeightChanged: {
                              console.log("scrollView.RowLayout::onHeightChanged", height);
                              /// @hack -> need to set position _before_ the middle of the text
      /*
                              if (textArea.length > 0 && textArea.cursorPosition == textArea.length) {
                                  textArea.cursorPosition = 0;
                              }
      */
                          }
                          TextArea {
                              id: textArea
                              verticalAlignment: TextEdit.AlignTop
                              wrapMode: TextArea.Wrap
                              background: null
                          }
                          background: Rectangle {
                              border.color: "red"
                              border.width: 1
                          }
                      }
                  }
              }
          }
      }
      
      

       

      0) Copy large enough text to the clipboard

      1) Tap on the TextArea (remember the y values)

      1. Keyboard is visible
      2. Whole view is lifted up by keyboard
      3. Qt.​inputMethod:​:​onKeyboardRectangleChanged x:​ 0 *y:​ 647* width:​ 375 height:​ 216
      4. Qt.​inputMethod:​:​onKeyboardRectangleChanged x:​ 0 *y:​ 907* width:​ 375 height:​ 216
      5. Qt.​inputMethod:​:​onKeyboardRectangleChanged x:​ 0 *y:​ 647* width:​ 375 height:​ 260

      2) Long press and wait for the system context menu with 'paste-suggestion'

      3) Tap paste

      1. Keyboard is visible
      2. Whole view is lifted down
      3. TextArea is visually blocked by keyboard
      4. TextArea has active focus
      5. Qt.inputMethod::onKeyboardRectangleChanged x: 0 y: 387 width: 375 height: 260
      Hack #1

      After third stage type any letter to the TextArea from virtual keyboard - whole view is lifted up again immediately.

      Hack #2

      Reset cursor position when scrollView height is changed

      onHeightChanged: {
          textArea.cursorPosition = 0;
      }
      
      Observation #1 (iOS specific)

      Implement @implementation iOSKeyboardListener : UIGestureRecognizer <UIGestureRecognizerDelegate> and observe: UIKeyboardWillShowNotification, UIKeyboardDidShowNotification, UIKeyboardWillHideNotification, UIKeyboardDidHideNotification, UIKeyboardDidChangeFrameNotification

      Nothing from this list is happening on the third stage which means that keyboardRectangle calculated independently in qiosinputcontext.mm
       

      Attachments

        1. qtbug1-demo.mp4
          3.57 MB
        2. qtbug1-src.zip
          7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            danilabagroff Daniil Megrabyan
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes