首页 > 其他分享 >Qt 虚拟键盘qtvirtualkeyboard遮挡QLineEdit问题

Qt 虚拟键盘qtvirtualkeyboard遮挡QLineEdit问题

时间:2024-02-27 13:25:29浏览次数:30  
标签:anchorHandleVisible anim Qt focusWindow globalAnchorRectangle qtvirtualkeyboard 

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 }

 

标签:anchorHandleVisible,anim,Qt,focusWindow,globalAnchorRectangle,qtvirtualkeyboard,
From: https://www.cnblogs.com/ybqjymy/p/18036687

相关文章

  • Qt Virtual Keyboard C++集成与实现(QWidget)
    一.设置1.配置所需语言1).通过QtCreator配置打开Qt工程文件,点开左侧 Projects->Build->BuildSteps->qmake->Additionalarguments在 Additionalarguments 增加配置参数:CONFIG+="lang-ar_ARlang-da_DKlang-de_DElang-en_GBlang-es_ESlang-fa_FAlang-fi_FIlang-fr......
  • Qt Virtual Keyboard C++集成与实现(解决模态对话框键盘失效问题)
    一.Qt模态对话框先让我们来看看对话框的几种特性:1.Qt::NonModaThewindowisnotmodalanddoesnotblockinputtootherwindows.2.Qt::WindowModalThewindowismodaltoasinglewindowhierarchyandblocksinputtoitsparentwindow,allgrandparentwin......
  • Qt QML 虚拟键盘(VirtualKeyboard )
    简介Qt官方开源了一个虚拟键盘的示例,该示例提供两种使用方式:一种用于桌面平台,另一种用于嵌入式平台,示例采用嵌入式平台方式显示。它们区别是前者脱离窗口应用于全局,后者依附于窗口。示例在QtCreator软件可以找到:或在以下Qt安装目录找到:C:\Qt\{你的Qt版本}\Examples......
  • Qt Virtual Keyboard 自适应位置
    一.实现inputcontex.h增加如下内容:1Q_PROPERTY(QRectFinputItemGeometryREADinputItemGeometry)2QRectFinputItemGeometry();inputcontex.cpp增加如下内容:1QRectFInputContext::inputItemGeometry()2{3QWidget*pInputItem=(QWidget*)inputItem();4......
  • Qt Virtual Keyboard实现自适应悬浮键盘(多种方法详细记录)
    项目需求实现悬浮键盘,点击QLineEdit或QTextEdit自动弹出自适应悬浮键盘,尝试了以下几种方法后选择了修改QTVirtualKeyboard源码。在这里把其他方法/想法也列出来做一下记录。项目环境:QT5.13.2VS2017方法1:调用windows自带系统软件盘介绍windows自带软键盘分为......
  • Qt QML使用虚拟键盘示例(附完整源码)
    使用"虚拟键盘"注意(例子的Qt版本:5.12.4)注意一:     /*必须在main.cpp开始处加入如下代码,否则无法使用"虚拟键盘"*/     qputenv(“QT_IM_MODULE”,QByteArray(“qtvirtualkeyboard”)); 注意二:     键盘大小是根据宽度自动计算的,所以,应用程序应该只设置Inpu......
  • Qt 常用基础设置
    //右键菜单无效setContextMenuPolicy(Qt::NoContextMenu);//设置窗口背景透明setAttribute(Qt::WA_TranslucentBackground);//设置外框隐藏setWindowFlag(Qt::FramelessWindowHint);//设置无焦点setFocusPolicy(Qt::NoFocus);//设置lineEdit未输入字时显示文字l......
  • QT多线程实现-----问题解决及实现方式
    一、概述恰巧正在做一个多线程通信的项目,具体功能是与下位机交互和文件发送,在子线程中实现命令发送和文件传输。使用movetothread主要遇到以下几个问题:1.Socketnotifierscannotbeenabledordisabledfromanotherthread。2.子线程完成文件传输,发送信号......
  • Qt的拖拽操作例子
    本文是一个拖拽文本的例子。演示了如何把按钮的标题拖拽到文本编辑框里。Qt对拖拽的封装很好,QDrag对象简单易用。本文程序测试环境是VS2017和Qt5.9。下面是程序拖拽时的效果图,可以看出来拖拽的时候光标下方也显示了文本内容:头文件。本功能是在主窗口中实现的。下面代码里QtTest......
  • 项目实战:Qt监测操作系统cpu温度v1.1.0(支持windows、linux、国产麒麟系统)
    需求  使用Qt软件开发一个检测cpu温度的功能。  兼容windows、linux,国产麒麟系统(同为linux)Demo  windows上运行(需要管理员权限):    国产麒麟操作上运行(需要管理员权限):   功能描述v1.1.0windows上定时检测输出cpu温度。linux上定时检测输出cpu......