QWidget中的QEvent :: KeyPress不会发出声音

时间:2016-10-13 15:39:28

标签: c++ qt

我有两个小工具。

我首先将第二个小部件加载到第一个小部件:

 NumpadService *numpadService = new NumpadService(this);
 ui->pinpadLayout->addWidget(numpadService,0,0);

pinpadLayout它只是QGirdLayout。

NumberService小部件有像pinpad这样的按钮。我想模拟按键以填充QEditLine,它是第一个小部件(不是pinpad)的属性。

我试过这样的方式:

QKeyEvent *event = new QKeyEvent (QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier, "0");
    QCoreApplication::postEvent (this->parentWidget(), event);

   if (event->isAccepted()) {
       QMessageBox::information(this, "", "ok");

   } else {
       QMessageBox::information(this, "", "bad");

   }

它显示确定,但QLineEdit仍为空。我必须使用物理键盘。我需要使用触摸屏。

提前致谢。

0 个答案:

没有答案