Qt5 Virtual Keyboard C++集成与实现三(解决模态对话框键盘失效问题)

前面我们已经介绍了:

  1. Qt5 Virtual Keyboard C++集成与实现一(基于QWidget的多语言键盘编译及自定义大小)
  2. Qt5 Virtual Keyboard C++集成与实现二(自适应位置)

当使用模态对话框时,点击对话框里的输入控件,弹出Qt键盘后键盘无法获得焦点的,这是由于模态对话框的特性所导致的,下面就让我们看看如何解决。

Qt5 Virtual Keyboard C++集成与实现三(解决模态对话框键盘失效问题)

一. Qt 模态对话框

先让我们来看看对话框的几种特性:

  1. Qt::NonModa
    The window is not modal and does not block input to other windows.
  2. Qt::WindowModal
    The window is modal to a single window hierarchy and blocks input to its parent window, all grandparent windows, and all siblings of its parent and grandparent windows.
  3. Qt::ApplicationModal
    The window is modal to the application and blocks input to all windows.

可以看出,比较常用的exec()方法显示的对话框是属于第三种:Qt::ApplicationModal,这种对话框无法接受除了自身之外的任何其他对象的输入,而第二种 Qt::WindowModal 是可以接受 QApplication 的输入,所以我们只需将其改为第二种即可。

二. 实现

我们只需在显示键盘之前添加如下代码:

        if(qGuiApp->focusWindow()->isModal())
            qGuiApp->focusWindow()->setModality(Qt::WindowModal);

现在再看,是不是可以正常使用Qt键盘了?

三. 更多键盘设置

  1. Qt5 Virtual Keyboard C++集成与实现一(基于QWidget的多语言键盘编译及自定义大小)
  2. Qt5 Virtual Keyboard C++集成与实现二(自适应位置)
0 0 投票数
喜欢就给个好评吧!
赞(0) 打赏
未经允许不得转载:爱易默博客 » Qt5 Virtual Keyboard C++集成与实现三(解决模态对话框键盘失效问题)
订阅评论
提醒
guest

0 评论
内联反馈
查看所有评论
免责声明:本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有,请在下载后24小时之内自觉删除,若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系站长删除,我们将及时处理! Disclaimer: Most of the download resources on this site are collected on the Internet, and are only used for learning and communication. The copyright belongs to the original author. Please consciously delete within 24 hours after downloading. If you use it for commercial purposes, please purchase the original version. If the content posted on this site violates your rights, please contact us to delete it, and we will deal with it in time!

联系我们 Contact us

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

0
希望看到您的想法,请您发表评论x