Qt5 Virtual Keyboard C++ Integration and Implementation III (Solving the Problem of Modal Dialog Keyboard Invalidation)

We have already introduced:

  1. Qt5 Virtual Keyboard C ++ Integration and Implementation I (Multilingual Keyboard Compilation and Custom Size Based on QWidget)
  2. Qt5 Virtual Keyboard C ++ Integration and Implementation II (Adaptive Position)

When using a modal dialog box, click the input control in the dialog box and the keyboard cannot get the focus after the Qt keyboard pops up. This is due to the characteristics of the modal dialog box. Let us see how to solve it.

Qt5 Virtual Keyboard C++ Integration and Implementation III (Solving the Problem of Modal Dialog Keyboard Invalidation)

I. Qt Modal Dialog

Let’s take a look at several features of the dialog box first:

  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.

It can be seen that the more commonly used exec () method displays a dialog box that belongs to the third type: Qt :: ApplicationModal. This type of dialog box cannot accept input from any object other than itself, and the second type Qt :: WindowModal can accept input from QApplication, so we just need to change it to the second one.

II. Implementation

We just need to add the following code before displaying the keyboard:

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

Now look, is it possible to use the Qt keyboard normally?

III. More Qt5 Virtual Keyboard Settings

  1. Qt5 Virtual Keyboard C ++ Integration and Implementation I (Multilingual Keyboard Compilation and Custom Size Based on QWidget)
  2. Qt5 Virtual Keyboard C ++ Integration and Implementation II (Adaptive Position)
0 0 votes
Article Rating
赞(0) 打赏
未经允许不得转载:iemblog » Qt5 Virtual Keyboard C++ Integration and Implementation III (Solving the Problem of Modal Dialog Keyboard Invalidation)
Subscribe
Notify of
guest

0 COMMENTS
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
免责声明:本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有,请在下载后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
Would love your thoughts, please comment.x
()
x