From b805c8d78151c250c517ec28f6f25b44f02d3ccf Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Wed, 17 May 2023 09:27:15 +0800 Subject: [PATCH] fix issue I7357J --- src-vpn/frontend/single-pages/vpnpage.cpp | 20 +++++++++++++++----- src/frontend/mainwindow.cpp | 22 ++++++++++++++++------ src/frontend/mainwindow.h | 1 + 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src-vpn/frontend/single-pages/vpnpage.cpp b/src-vpn/frontend/single-pages/vpnpage.cpp index 17a831ce..7bd2a0ec 100644 --- a/src-vpn/frontend/single-pages/vpnpage.cpp +++ b/src-vpn/frontend/single-pages/vpnpage.cpp @@ -45,11 +45,11 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent) connect(m_vpnConnectOperation, &KyVpnConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); connect(m_vpnConnectOperation, &KyVpnConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); - connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){ - if (activeWindowId != this->winId() && activeWindowId != 0) { - hide(); - } - }); +// connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){ +// if (activeWindowId != this->winId() && activeWindowId != 0) { +// hide(); +// } +// }); } VpnPage::~VpnPage() @@ -575,6 +575,16 @@ bool VpnPage::eventFilter(QObject *watched, QEvent *event) } } + if (watched == this) { + //失焦退出 + if (event->type() == QEvent::ActivationChange) { + if (QApplication::activeWindow() != this) { + hide(); + return true; + } + } + } + return QWidget::eventFilter(watched, event); } diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index 2ba37140..8b79a573 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -160,6 +160,7 @@ void MainWindow::firstlyStart() initWindowTheme(); initTrayIcon(); initPlatform(); + installEventFilter(this); m_secondaryStartTimer = new QTimer(this); connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() { m_secondaryStartTimer->stop(); @@ -263,6 +264,21 @@ void MainWindow::paintEvent(QPaintEvent *event) // painter.drawRoundedRect(rect, 12, 12); //窗口圆角 } +bool MainWindow::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == this) { + //失焦退出 + if (event->type() == QEvent::ActivationChange) { + if (QApplication::activeWindow() != this) { + hideMainwindow(); + return true; + } + } + } + + return QObject::eventFilter(watched, event); +} + void MainWindow::initTransparency() { if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) { @@ -403,12 +419,6 @@ void MainWindow::initDbusConnnect() QString("/"), QString("com.kylin.statusmanager.interface"), QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); - - connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ - if (activeWindowId != this->winId() && activeWindowId != 0) { - hideMainwindow(); - } - }); } /** diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index 72785fff..c231f3fb 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -144,6 +144,7 @@ public Q_SLOTS: protected: void keyPressEvent(QKeyEvent *event); void paintEvent(QPaintEvent *event); + bool eventFilter(QObject *watched, QEvent *event); private: void firstlyStart(); //一级启动