为什么虚拟键盘不适用于Qt中的QDialog文本框?

时间:2016-06-15 04:32:26

标签: c++ qt

我为无键盘设备做了一个应用程序。 我将thisRef用作键盘作为虚拟键盘。 我的项目中有一个对话框,其中有两个文本框(其中一个用于输入用户名,另一个用于输入密码),带有两个按钮:确定和取消。在构建项目并运行之后,按菜单按钮显示菜单表单,然后出现对话框以检查用户身份验证。用户应在虚拟键盘的文本框中输入数据。 出现虚拟键盘(thisRef中的输入面板),但按钮不起作用。 当我搜索时,我看到了"sounds like you are trying to open another window from the dialog - this is your error. Of course the dialog will stay on top - that is its job." 因为对话框是模态的,所以虚拟键盘是禁用的 是否有编辑对话框或键盘在模态小部件中工作?

main.cpp

#include "mainwindow.h"
#include <QApplication>
#include "myinputpanelcontext.h"


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MyInputPanelContext *ic= new MyInputPanelContext; ;
    a.setInputContext(ic);

    MainWindow w;
    //w.show();
    w.showFullScreen();
    w.centralWidget()->releaseKeyboard();
    return a.exec();
}

MainWindow.cpp:

MyDialog *d=new MyDialog(this);
d.exec();

1 个答案:

答案 0 :(得分:1)

它解决了:

使用exec()启动模态对话框,它们在嵌套事件循环运行时阻止程序流。 使用show()启动无模式对话框,它们不会阻止程序流。

来自http://www.qtforum.org/article/14285/modeless-dialog.html 我使用这段代码:

 MyDialog *d=new MyDialog(this);
   d->show();
   d->raise();
   q->activewindows();

代替此代码:

MyDialog *d=new MyDialog(this);
   d.exec();

作为文件参考:

  

无模式对话框:void EditorWindow :: find(){

    if (!findDialog) {
>         findDialog = new FindDialog(this);
>         connect(findDialog, SIGNAL(findNext()), this, SLOT(findNext()));
>     } findDialog->show();
>     findDialog->raise();
>     findDialog->activateWindow(); }
  

来自here