void MainForm::keyEvent (QKeyEvent *event){switch (event->key()) { case Key_Up: if (event->state() & ShiftButton) //??? event->accept(); else //??? event->accept(); break; //обработка еще 3х вариантов default: QWidget::keyPressEvent(event); } }
protected: void keyPressEvent(QKeyEvent *e);
void MainForm::keyPressEvent (QKeyEvent *event){ if (event->key()==Qt::Key_Z) { qDebug("Event accepted"); event->accept(); } else { event->ignore(); }}
bool MainForm::eventFilter(QObject *target, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); if(keyEvent->key()==Qt::Key_Z) qDebug("Event accepted"); return QObject::eventFilter(target, event); } return QObject::eventFilter(target, event);}
C++ (Qt)bool MainForm::event(QEvent *e) { if(e->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent *) e; if(keyEvent->key() == Key_Z) { qDebug("Event accepted"); return QWidget::event(e); } } return QWidget::event(e);}