点击窗口外其他地方关闭
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
窗口失去焦点关闭
1.示例一
bool testWidget::eventFilter(QObject *obj, QEvent *event){if (Q_NULLPTR == obj) {return false;}if (QEvent::ActivationChange == event->type()) {if(QApplication::activeWindow() != this){this->close();}}return QWidget::eventFilter(obj, event);}
2.示例二
bool testWidget::event(QEvent * event){if (QEvent::ActivationChange == event->type()) {if (QApplication::activeWindow() != this){this->close();}}return QWidget::event(event);}