如何在离开(关闭或失去焦点)窗口之前显示模态确认消息
How to show a modal confirmation message before leaving (closing or losing focus) of a window?
我想在用户离开(alt + tab(关闭或松散焦点))主窗口之前显示确认消息框并阻止屏幕。如何做到这一点?
这是我的代码
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMainWindow::showFullScreen();
this->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event){
if(event->type() == 128){
QMessageBox::information(this, "title", "text", QMessageBox::Ok | QMessageBox::Cancel);
return true;
}
return true;
}
对于关闭事件:
在MainWindow类中重新实现closeEvent
方法。链接对于窗口激活和取消激活事件,请尝试以下操作:
bool MainWindow::event(QEvent * e) // overloading event(QEvent*) method of QMainWindow
{
switch(e->type())
{
// ...
case QEvent::WindowActivate :
// gained focus
break ;
case QEvent::WindowDeactivate :
// lost focus
break ;
// ...
} ;
return QMainWindow::event(e) ;
}
相关文章:
- 如果不在窗口 10 中声明名为 openCV 的 openCV namedWindow,QT 图像显示将无法正常工作
- Visual Studio 2017 停止工作,并在打开后显示许多控制台窗口
- 在 GLFW 窗口中显示 FFMPEG 解码帧
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 为什么输出窗口上没有显示输出?
- C++ 窗口显示无框图像
- 如何使用Qt在新窗口中显示视频帧
- 如何以编程方式使窗口全屏显示?
- 强制将以SW_HIDE启动的进程中的窗口显示为STARTUPINFO
- 制作垫子类型对象的数组.输出窗口显示同一帧
- Gtk::在将我的gtkmm2移植到gtkmm3应用程序时,窗口显示并退出
- OpenGL:新窗口显示当前打开的窗口的内容
- WINAPI 创建窗口显示奇怪的结果
- 为什么通过CreateProcess调用的程序的窗口显示为SW_HIDE和CREATE_NO_INDOW
- 输出窗口显示三个图像,而不是一个
- 分窗口显示一个软件,总是在最上面
- WINAPI -窗口显示在调试版本中,而不是在发布版本中
- 在Visual Studio中使用本地Windows调试器运行第一个程序。输出窗口显示大量"Cannot find or open the PDB file"
- 我们如何防止控制台窗口显示在Visual Studio下
- 更新窗口显示OpenGL/GLUT c++