!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::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);
}

View File

@ -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();
}
});
}
/**

View File

@ -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(); //一级启动