我想在用戶離開之前顯示確認消息框並阻止屏幕(alt + tab(關閉或鬆散焦點))MainWindow。這個怎麼做?如何在離開(關閉或失去焦點)窗口之前顯示模式確認消息?
這裏是我的代碼
#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;
}
如果用戶「離開」你的窗口,你的窗口失去焦點* *,就表示該事件。然而,嘮叨用戶是因爲這不是我認爲好的UI設計,並且會刺激用戶(我知道這會刺激我)很多。 –
另外,失去焦點的窗口與正在關閉的窗口完全不同。您可能希望將標題更新爲更適合的內容。 –
我想在點擊「確定」或「取消」按鈕之前屏蔽屏幕。這對我的應用程序非常重要。這不是平常的應用。我有Web視圖中它,如果用戶要打開不同的程序(點擊OK)我有發送請求到服務器(調用RESTful Web服務) – gogagubi