我正在写一个键盘测试器,所以我用
开始一个对话框keybDialog keyboardTestWindow;
keyboardTestWindow.setWindowTitle("Keyboard test");
keyboardTestWindow.exec();
覆盖keyPressEvent(QKeyEvent *event)
,测试工作精湛。现在,我需要使用来自父级的一些参数,所以我做了
keybDialog keyboardTestWindow(m_parent);
keyboardTestWindow.setWindowTitle("Keyboard test");
keyboardTestWindow.exec();
并实施了我需要的东西。现在我发现只是通过实例化类并将父类传递给它,我的对话框不再接收keyPressEvent
。这些是以某种方式传递给m_parent
的吗?我怎么能避免这个?
编辑:
我keyPressEvent
的开头:
void keybDialog::keyPressEvent(QKeyEvent *event)
{
ui->txtBxKeyboardInput->clear();
qDebug() << "Event: " << hex << event->key() << event->nativeVirtualKey() << event->modifiers() << event->nativeModifiers() << event->nativeScanCode();
ui->txtBxKeyboardInput->setText(ui->txtBxKeyboardInput->text()+event->text());
switch(sequenceNumber)
{
case 0: // Left Shift + R
if( (event->key() == Qt::Key_R) && event->modifiers() == Qt::ShiftModifier && event->nativeModifiers() == 0x201)
{
reportSuccessfullKey(sequenceNumber);
}
else
{
ui->lblStatus->setText("WRONG");
}
break;