我新建了一个类MApplication,该类继承了QApplication。在MApplication中我重写了notify函数,在函数中我将试图将某些事件打印出来,具体如下图所示:
可以这么说,每一个事件执行前,都要经过QApplication::notify
,所以,我们可以重写notify
来对事件做特殊处理。
bool QApplication::notify(QObject *receiver, QEvent *event)
{
...
switch (e->type()) {
...
case QEvent::Wheel: // User input and window activation makes tooltips sleep
case QEvent::ActivationChange:
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::FocusOut:
case QEvent::FocusIn:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
...
res = d->notify_helper(receiver, e);
...
}