We have already introduced:
- Qt5 Virtual Keyboard C ++ Integration and Implementation I (Multilingual Keyboard Compilation and Custom Size Based on QWidget)
- 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:
- Qt::NonModa
The window is not modal and does not block input to other windows. - 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. - 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
- Qt5 Virtual Keyboard C ++ Integration and Implementation I (Multilingual Keyboard Compilation and Custom Size Based on QWidget)
- Qt5 Virtual Keyboard C ++ Integration and Implementation II (Adaptive Position)