<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[show confirmation message and block screen before leave(close or loose focus) main window[SOLVED]]]></title><description><![CDATA[<p dir="auto">I want to show confirmation messagebox and block the screen before user leaves(alt + tab (close or loose focus) ) MainWindow. how to do this?</p>
<p dir="auto"><strong>here is my code</strong></p>
<pre><code>#include "mainwindow.h"
#include "ui_mainwindow.h"
#include &lt;QMessageBox&gt;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
    QMainWindow::showFullScreen();
    this-&gt;installEventFilter(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

bool MainWindow::eventFilter(QObject *obj, QEvent *event){
    if(event-&gt;type() == 128){
        QMessageBox::information(this, "title", "text", QMessageBox::Ok | QMessageBox::Cancel);

        return true;
    }

    return true;
}

</code></pre>
]]></description><link>https://forum.qt.io/topic/58902/show-confirmation-message-and-block-screen-before-leave-close-or-loose-focus-main-window-solved</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 14:21:33 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/58902.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Sep 2015 06:51:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to show confirmation message and block screen before leave(close or loose focus) main window[SOLVED] on Thu, 17 Sep 2015 08:27:50 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for reply. I also used</p>
<pre><code>this-&gt;setWindowFlags(Qt::WindowStaysOnTopHint);
</code></pre>
<p dir="auto">and</p>
<pre><code>QMainWindow::showFullScreen();
</code></pre>
<p dir="auto">to stay my confirmation message on top. that was my goal.</p>
]]></description><link>https://forum.qt.io/post/290562</link><guid isPermaLink="true">https://forum.qt.io/post/290562</guid><dc:creator><![CDATA[Giorgi]]></dc:creator><pubDate>Thu, 17 Sep 2015 08:27:50 GMT</pubDate></item><item><title><![CDATA[Reply to show confirmation message and block screen before leave(close or loose focus) main window[SOLVED] on Wed, 16 Sep 2015 08:42:00 GMT]]></title><description><![CDATA[<p dir="auto">if you have <code>QMainWindow</code> you can subclass <code>closeEvent</code><br />
if you have <code>QDialog</code> then you should subclass <code>reject</code></p>
<p dir="auto"><code>QMainWindow</code> example :</p>
<pre><code>void MainWindow::closeEvent (QCloseEvent *event)
{
    QMessageBox::StandardButton resBtn = 
    QMessageBox::question( this, APP_NAME,tr("You sure?\n"),
    QMessageBox::Cancel | QMessageBox::No | QMessageBox::Yes,
    QMessageBox::Yes);
    if (resBtn != QMessageBox::Yes)
    {
        event-&gt;ignore();
    } 
   else
    {
        event-&gt;accept();
    }
}
</code></pre>
<p dir="auto"><code>QDialog</code> example :</p>
<pre><code>void MyDialog::reject()
{
    QMessageBox::StandardButton resBtn = QMessageBox::Yes;
    if (changes)
    {
        resBtn = QMessageBox::question( this, APP_NAME,
                 tr("You sure?\n"),
                 QMessageBox::Cancel | QMessageBox::No |
                 QMessageBox::Yes, QMessageBox::Yes);
    }
    if (resBtn == QMessageBox::Yes) 
   {
        QDialog::reject();
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/290460</link><guid isPermaLink="true">https://forum.qt.io/post/290460</guid><dc:creator><![CDATA[Hamed]]></dc:creator><pubDate>Wed, 16 Sep 2015 08:42:00 GMT</pubDate></item></channel></rss>