diff --git a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java index 8bc4f569b70..41256cc64a1 100644 --- a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java +++ b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java @@ -135,7 +135,15 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener initOverlay(); final int[] layoutLocation = new int[2]; - m_layout.getLocationOnScreen(layoutLocation); + + // m_layout is QtEditText. Since it doesn't match the QtWindow size, we should use its + // parent for cursorHandle positioning. However, there may be cases where the parent is + // not set. In such cases, we need to use QtEditText instead. + View positioningView = (View) m_layout.getParent(); + if (positioningView == null) + positioningView = m_layout; + + positioningView.getLocationOnScreen(layoutLocation); // These values are used for handling split screen case final int[] activityLocation = new int[2]; @@ -158,7 +166,7 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener m_popup.update(x2, y2, -1, -1); m_cursorView.adjusted(x - m_posX, y - m_posY); } else { - m_popup.showAtLocation(m_layout, 0, x2, y2); + m_popup.showAtLocation(positioningView, 0, x2, y2); } m_posX = x; diff --git a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java index 241b8194439..cf7db14fff8 100644 --- a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java +++ b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java @@ -57,7 +57,14 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout Point viewSize = m_view.getCalculatedSize(); final int[] layoutLocation = new int[2]; - m_editText.getLocationOnScreen(layoutLocation); + + // Since QtEditText doesn't match the QtWindow size, we should use its parent for + // EditPopupMenu positioning. However, there may be cases where the parent is + // not set. In such cases, we need to use QtEditText instead. + View positioningView = (View) m_editText.getParent(); + if (positioningView == null) + positioningView = m_editText; + positioningView.getLocationOnScreen(layoutLocation); // These values are used for handling split screen case final int[] activityLocation = new int[2]; @@ -87,8 +94,8 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout } } - if (m_editText.getWidth() < x + viewSize.x / 2) - x2 = m_editText.getWidth() - viewSize.x; + if (positioningView.getWidth() < x + viewSize.x / 2) + x2 = positioningView.getWidth() - viewSize.x; if (x2 < 0) x2 = 0; @@ -96,7 +103,7 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout if (m_popup.isShowing()) m_popup.update(x2, y2, -1, -1); else - m_popup.showAtLocation(m_editText, 0, x2, y2); + m_popup.showAtLocation(positioningView, 0, x2, y2); m_posX = x; m_posY = y; diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEditText.java b/src/android/jar/src/org/qtproject/qt/android/QtEditText.java index 7f9fd0ff171..00928cfc88e 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEditText.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEditText.java @@ -269,7 +269,7 @@ class QtEditText extends View break; case CursorHandleShowNormal: if (m_cursorHandle == null) { - m_cursorHandle = new CursorHandle((Activity) getContext(), (View) getParent(), + m_cursorHandle = new CursorHandle((Activity) getContext(), this, CursorHandle.IdCursorHandle, android.R.attr.textSelectHandle, false); }