...protected: bool eventFilter(QObject * obj, QEvent *event);...
ui->centralWidget->installEventFilter(this);
bool MainWindow::eventFilter(QObject *obj, QEvent *event){ if ((event->type() == QEvent::MouseButtonPress)) { QMessageBox mes; mes.setText(obj->objectName()); mes.exec(); }}
ui->QTableView_obj->installEventFilter(this);
C++ (Qt)bool QApplication::notify( QObject* receiver, QEvent* e )
return false;
return true;
C++ (Qt)bool MyApplication::notify(QObject *receiver, QEvent *e){ qDebug() << receiver->objectName(); QPushButton *button = qobject_cast<QPushButton*>(receiver); if (button) button->setText("Work!"); QApplication::notify(receiver, e);}
bool QApplication::notify(QObject *obj, QEvent *event){ return false;}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){...qApp->installEventFilter(this);....}bool MainWindow::eventFilter(QObject *obj, QEvent *event){ if ((event->type() == QEvent::MouseButtonPress)&&(obj == ui->Mnemo)&&(FixFlag)) { .... } return false;}
bool QApplication::notify(QObject *obj, QEvent *event){ if ((event->type() == QEvent::MouseButtonPress)) { QMessageBox mes; mes.setText(obj->objectName()); mes.exec(); } return false;}