Вы должны перезаписать метод уведомления QApplication (или QGuiApplication):
#include <QtWidgets>
class Application: public QApplication
{
public:
using QApplication::QApplication;
bool notify(QObject *receiver, QEvent *e) override
{
if(receiver->isWindowType()){
if(e->type() == QEvent::Show){
qDebug()<< receiver << "show";
}
else if (e->type() == QEvent::Close) {
qDebug()<< receiver << "close";
}
}
return QApplication::notify(receiver, e);
}
};
int main(int argc, char *argv[])
{
Application a(argc, argv);
QMainWindow m;
QDialog d;
QWidget w;
m.show();
d.show();
w.show();
return a.exec();
}
Обновление:
#include <QtWidgets>
class Application: public QApplication
{
public:
using QApplication::QApplication;
bool notify(QObject *receiver, QEvent *e) override
{
if(receiver->isWidgetType()){
QWidget *w = qobject_cast<QWidget *>(receiver);
if(w->isWindow()){
if(e->type() == QEvent::Show){
qDebug()<< w << "show";
}
else if (e->type() == QEvent::Close) {
qDebug()<< w << "close";
}
}
}
return QApplication::notify(receiver, e);
}
};