!49 失焦逻辑修改

Merge pull request !49 from zhaoshixu/0517
This commit is contained in:
zhaoshixu 2023-05-17 01:52:50 +00:00 committed by Gitee
commit 78a0fc2f93
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 32 additions and 11 deletions

View File

@ -45,11 +45,11 @@ VpnPage::VpnPage(QWidget *parent) : SinglePage(parent)
connect(m_vpnConnectOperation, &KyVpnConnectOperation::activateConnectionError, this, &VpnPage::activateFailed); connect(m_vpnConnectOperation, &KyVpnConnectOperation::activateConnectionError, this, &VpnPage::activateFailed);
connect(m_vpnConnectOperation, &KyVpnConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed); connect(m_vpnConnectOperation, &KyVpnConnectOperation::deactivateConnectionError, this, &VpnPage::deactivateFailed);
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){ // connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, [&](WId activeWindowId){
if (activeWindowId != this->winId() && activeWindowId != 0) { // if (activeWindowId != this->winId() && activeWindowId != 0) {
hide(); // hide();
} // }
}); // });
} }
VpnPage::~VpnPage() 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); return QWidget::eventFilter(watched, event);
} }

View File

@ -160,6 +160,7 @@ void MainWindow::firstlyStart()
initWindowTheme(); initWindowTheme();
initTrayIcon(); initTrayIcon();
initPlatform(); initPlatform();
installEventFilter(this);
m_secondaryStartTimer = new QTimer(this); m_secondaryStartTimer = new QTimer(this);
connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() { connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() {
m_secondaryStartTimer->stop(); m_secondaryStartTimer->stop();
@ -263,6 +264,21 @@ void MainWindow::paintEvent(QPaintEvent *event)
// painter.drawRoundedRect(rect, 12, 12); //窗口圆角 // 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() void MainWindow::initTransparency()
{ {
if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) { if(QGSettings::isSchemaInstalled(TRANSPARENCY_GSETTINGS)) {
@ -403,12 +419,6 @@ void MainWindow::initDbusConnnect()
QString("/"), QString("/"),
QString("com.kylin.statusmanager.interface"), QString("com.kylin.statusmanager.interface"),
QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool))); QString("mode_change_signal"), this, SLOT(onTabletModeChanged(bool)));
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){
if (activeWindowId != this->winId() && activeWindowId != 0) {
hideMainwindow();
}
});
} }
/** /**

View File

@ -144,6 +144,7 @@ public Q_SLOTS:
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
private: private:
void firstlyStart(); //一级启动 void firstlyStart(); //一级启动