diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 7792535..60982f2 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -32,6 +32,7 @@ #if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)) #include #include + #endif #include #include "ukuistylehelper/ukuistylehelper.h" @@ -81,11 +82,12 @@ MainWindow::MainWindow(QWidget *parent) : initConnections(); initGsettings(); - connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ - if (activeWindowId != this->winId()) { - tryHideMainwindow(); - } - }); +// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ +// qDebug() << "activeWindowChanged!!!" << activeWindowId; +// if (activeWindowId != this->winId()) { +// tryHideMainwindow(); +// } +// }); //NEW_TODO, register plugins // SearchPluginManager::getInstance()->registerPlugin(\\); @@ -571,11 +573,21 @@ void MainWindow::paintEvent(QPaintEvent *event) { bool MainWindow::eventFilter(QObject *watched, QEvent *event) { - //kwin alt+f4发出close事件, 需要在存在子窗口时屏蔽该事件 - if ((watched == this) && (event->type() == QEvent::Close)) { - event->ignore(); - tryHideMainwindow(); - return true; + if (watched == this) { + //失焦退出 + if (event->type() == QEvent::ActivationChange) { + if (QApplication::activeWindow() != this) { + tryHideMainwindow(); + return true; + } + } + //kwin alt+f4发出close事件, 需要在存在子窗口时屏蔽该事件 + if (event->type() == QEvent::Close) { + event->ignore(); + tryHideMainwindow(); + return true; + } } + return QObject::eventFilter(watched, event); }