一. 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
的输入,所以我们只需将其改为第二种即可。
二. 实现
我们只需在显示键盘之前添加如下代码:
1 if(qGuiApp->focusWindow()->isModal()) 2 qGuiApp->focusWindow()->setModality(Qt::WindowModal);
标签:Qt,对话框,windows,C++,window,WindowModal,input From: https://www.cnblogs.com/ybqjymy/p/18036117