Created
August 21, 2019 03:15
-
-
Save huihut/7e91776049231c7164f8f725fc9ebb1a to your computer and use it in GitHub Desktop.
Qt Dialog 点击窗口外隐藏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 重写事件 | |
bool event(QEvent *event) | |
{ | |
if (event->type() == QEvent::ActivationChange) | |
{ | |
if (QApplication::activeWindow() != this) | |
{ | |
this->hide(); | |
} | |
} | |
return QWidget::event(event); | |
} | |
// 重写事件过滤器 | |
// 需要初始化过滤器:installEventFilter(this); | |
bool eventFilter(QObject *o, QEvent *e) | |
{ | |
if (QEvent::WindowDeactivate == e->type() && QApplication::activeWindow() != this) | |
{ | |
hide(); | |
} | |
return QWidget::eventFilter(o, e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment