1.通过修改虚拟键盘源码
qtvirtualkeyboard-everywhere-src-5.14.2\src\virtualkeyboard\desktopinputselectioncontrol.cpp:159
1 void DesktopInputSelectionControl::updateVisibility()
2 {
3 static int originalY = 0;
4 if (!m_enabled) {
5 // if VKB is hidden, we must hide the selection handles immediately,
6 // because it might mean that the application is shutting down.
7 m_anchorSelectionHandle->hide();
8 m_cursorSelectionHandle->hide();
9 m_anchorHandleVisible = false;
10 m_cursorHandleVisible = false;
11
12 if(originalY != 0)
13 {
14 if (QWindow *focusWindow = QGuiApplication::focusWindow()) {
15 focusWindow->setY(originalY);
16 }
17 originalY = 0;
18 }
19
20 return;
21 }
22 const bool wasAnchorVisible = m_anchorHandleVisible;
23 const bool wasCursorVisible = m_cursorHandleVisible;
24 const bool makeVisible = (m_inputContext->isSelectionControlVisible() || m_handleState == HandleIsMoving) && m_enabled;
25
26 m_anchorHandleVisible = makeVisible;
27 if (QWindow *focusWindow = QGuiApplication::focusWindow()) {
28 QRectF globalAnchorRectangle = m_inputContext->anchorRectangle();
29 QPoint tl = focusWindow->mapToGlobal(globalAnchorRectangle.toRect().topLeft());
30 globalAnchorRectangle.moveTopLeft(tl);
31 m_anchorHandleVisible = m_anchorHandleVisible
32 && m_inputContext->anchorRectIntersectsClipRect()
33 && !(m_inputContext->priv()->keyboardRectangle().intersects(globalAnchorRectangle));
34
35 QRectF keyboardRec = m_inputContext->priv()->keyboardRectangle();
36 if(keyboardRec.intersects(globalAnchorRectangle))
37 {
38 int moveY = globalAnchorRectangle.bottomLeft().y() - keyboardRec.y();
39 originalY = focusWindow->y();
40 int newY = originalY - moveY - 10;
41 focusWindow->setY(newY);
42 }
43 }
44
45 if (wasAnchorVisible != m_anchorHandleVisible) {
46 const qreal end = m_anchorHandleVisible ? 1 : 0;
47 if (m_anchorHandleVisible)
48 m_anchorSelectionHandle->show();
49 QPropertyAnimation *anim = new QPropertyAnimation(m_anchorSelectionHandle.data(), "opacity");
50 anim->setEndValue(end);
51 anim->start(QAbstractAnimation::DeleteWhenStopped);
52 }
53
54 m_cursorHandleVisible = makeVisible;
55 if (QWindow *focusWindow = QGuiApplication::focusWindow()) {
56 QRectF globalCursorRectangle = m_inputContext->cursorRectangle();
57 QPoint tl = focusWindow->mapToGlobal(globalCursorRectangle.toRect().topLeft());
58 globalCursorRectangle.moveTopLeft(tl);
59 m_cursorHandleVisible = m_cursorHandleVisible
60 && m_inputContext->cursorRectIntersectsClipRect()
61 && !(m_inputContext->priv()->keyboardRectangle().intersects(globalCursorRectangle));
62
63 }
64
65 if (wasCursorVisible != m_cursorHandleVisible) {
66 const qreal end = m_cursorHandleVisible ? 1 : 0;
67 if (m_cursorHandleVisible)
68 m_cursorSelectionHandle->show();
69 QPropertyAnimation *anim = new QPropertyAnimation(m_cursorSelectionHandle.data(), "opacity");
70 anim->setEndValue(end);
71 anim->start(QAbstractAnimation::DeleteWhenStopped);
72 }
73 }