<?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[How to handle QMessageBox when user click outside of MessageBox]]></title><description><![CDATA[<p dir="auto">hi, my problem was i have created a QMessageBox properly in raspberry pi but my problem was when i click on outside of the messagebox window application takes default as no. My need is when user click outside of the messageBox application must wont response for that event only the message box button should work at that time. Can you help me to do that. Below i have added my messageBox code</p>
<pre><code>void MainWindow::on_pushButton_Shutdown_clicked()
{
    qDebug()&lt;&lt;"entered shutdown message box";
    QMessageBox msg(this);
    msg.setWindowFlags(Qt::Popup);
    msg.setStyleSheet("font: 75 20pt Liberation Serif ;");
    QPixmap pix("/home/pi/git/FIA_Validation/FIA/notification.png");
    auto newPixmap = pix.scaled(65, 65);
    msg.setIconPixmap(newPixmap);
    msg.setStyleSheet("font:16pt Arial;");
    msg.setText("Are you sure you want to power off ?");
    msg.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
    msg.setDefaultButton(QMessageBox::NoButton);
    msg.setButtonText(QMessageBox::Ok , "Yes");
    msg.setButtonText(QMessageBox::No , "Go back");
    msg.setFixedWidth(500);
    if(msg.exec() == QMessageBox::Ok)
    {
        system("sudo poweroff");  //System Power Off Option
    }
    else
    {

    }

}
</code></pre>
]]></description><link>https://forum.qt.io/topic/157376/how-to-handle-qmessagebox-when-user-click-outside-of-messagebox</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 12:50:23 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/157376.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Jun 2024 07:16:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 12:17:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mohan-raj">@<bdi>Mohan-Raj</bdi></a><br />
Works for me under Qt5 and Xorg.<br />
Obviously I don't have RPi.  Are you perchance running under Wayland?  If/assuming so, you probably won't be able to do much about changing stuff like this as Wayland likely doesn't allow it.  Can you try under Xorg?</p>
<p dir="auto">On a separate matter or if this is the case.  I do not know why you want to change this stuff.  Leave message boxes etc. with whatever furniture is usual, that's standard for the windowing system.  If you insist, try creating your own window with as little inbuilt stuff as possible, e.g. don't use <code>QMessageBox</code> or <code>Dialog</code> style and see where you get to.</p>
]]></description><link>https://forum.qt.io/post/803266</link><guid isPermaLink="true">https://forum.qt.io/post/803266</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 22 Jun 2024 12:17:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 12:01:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Yes you are right, its working properly when i see in Debug() but in application UI output the close ,minimize or not disabled or hidden working asusual.<br />
UI output<br />
<img src="https://ddgobkiprc33d.cloudfront.net/be90fc2e-5d8c-4028-8941-e20cf50e8e62.png" alt="MESSAGEBOX.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Debug Output<br />
<img src="https://ddgobkiprc33d.cloudfront.net/2ef75c4b-8031-41f0-bb85-b8b588137a38.png" alt="DEBUG.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/803264</link><guid isPermaLink="true">https://forum.qt.io/post/803264</guid><dc:creator><![CDATA[Mohan Raj]]></dc:creator><pubDate>Sat, 22 Jun 2024 12:01:38 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 09:54:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mohan-raj">@<bdi>Mohan-Raj</bdi></a> said in <a href="/post/803254">How to handle QMessageBox when user click outside of MessageBox</a>:</p>
<blockquote>
<p dir="auto">but the way you gave also not working.</p>
</blockquote>
<p dir="auto">I suggest my code <em>is</em> working!  (Yours just plain did wrong thing.)  You could verify by <code>qDebug() &lt;&lt; msg.windowFlags()</code> to check those two have indeed been switched off.  Output before and after my code:</p>
<pre><code>QFlags&lt;Qt::WindowType&gt;(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint|WindowCloseButtonHint)
QFlags&lt;Qt::WindowType&gt;(Dialog|MSWindowsFixedSizeDialogHint|WindowTitleHint|WindowSystemMenuHint)
</code></pre>
<p dir="auto">Which shows the code works correctly, yet the message box still shows the "close" box.  I don't know if that is a feature of the standard/native <code>QMessageBox</code>.  Looks like adding</p>
<pre><code>msg.setWindowFlag(Qt::CustomizeWindowHint, true);
</code></pre>
<p dir="auto">allows it to be removed.</p>
]]></description><link>https://forum.qt.io/post/803255</link><guid isPermaLink="true">https://forum.qt.io/post/803255</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 22 Jun 2024 09:54:19 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 09:23:40 GMT]]></title><description><![CDATA[<p dir="auto">but the way you gave also not working. Okay that's fine I'll play further, Thanks for your cooperation</p>
]]></description><link>https://forum.qt.io/post/803254</link><guid isPermaLink="true">https://forum.qt.io/post/803254</guid><dc:creator><![CDATA[Mohan Raj]]></dc:creator><pubDate>Sat, 22 Jun 2024 09:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 08:18:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mohan-raj">@<bdi>Mohan-Raj</bdi></a><br />
Your code is wrong, in a couple of ways.  You meant:</p>
<pre><code>msg.setWindowFlag(Qt::WindowMinimizeButtonHint, false);
msg.setWindowFlag(Qt::WindowCloseButtonHint, false);
</code></pre>
<p dir="auto">Having said that, I don't actually find that suppresses the close button at least, Qt5 under Ubuntu Xorg.  You'll have to play.</p>
]]></description><link>https://forum.qt.io/post/803249</link><guid isPermaLink="true">https://forum.qt.io/post/803249</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 22 Jun 2024 08:18:29 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 08:07:55 GMT]]></title><description><![CDATA[<p dir="auto">yes, you are right but if i use these flags messageBox was not opened or pop up<br />
msg.setWindowFlags(Qt::WindowMinimizeButtonHint);<br />
msg.setWindowFlags(Qt::WindowCloseButtonHint);</p>
]]></description><link>https://forum.qt.io/post/803248</link><guid isPermaLink="true">https://forum.qt.io/post/803248</guid><dc:creator><![CDATA[Mohan Raj]]></dc:creator><pubDate>Sat, 22 Jun 2024 08:07:55 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 07:53:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mohan-raj">@<bdi>Mohan-Raj</bdi></a><br />
I haven't looked into it, but there are flags for removing the "furniture" buttons like "minimize", "maximize" or "close".</p>
]]></description><link>https://forum.qt.io/post/803246</link><guid isPermaLink="true">https://forum.qt.io/post/803246</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 22 Jun 2024 07:53:23 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 07:42:51 GMT]]></title><description><![CDATA[<p dir="auto">i have a problem on removing that when i remove it, this shows with minimize and close options in frame when i click on that minimize it minimizes my whole application and also sometimes when i close the message box by using the frame option it also perform like that so please can you help me with any other options</p>
]]></description><link>https://forum.qt.io/post/803245</link><guid isPermaLink="true">https://forum.qt.io/post/803245</guid><dc:creator><![CDATA[Mohan Raj]]></dc:creator><pubDate>Sat, 22 Jun 2024 07:42:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to handle QMessageBox when user click outside of MessageBox on Sat, 22 Jun 2024 07:35:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mohan-raj">@<bdi>Mohan-Raj</bdi></a> said in <a href="/post/803242">How to handle QMessageBox when user click outside of MessageBox</a>:</p>
<blockquote>
<p dir="auto">My need is when user click outside of the messageBox application must wont response for that event only the message box button should work at that time.</p>
</blockquote>
<p dir="auto">That is what it normally does.  It is because you added <code>msg.setWindowFlags(Qt::Popup);</code> that it behaves the way you report.  "Popup" means "click outside closes".  So don't do that!</p>
]]></description><link>https://forum.qt.io/post/803244</link><guid isPermaLink="true">https://forum.qt.io/post/803244</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 22 Jun 2024 07:35:50 GMT</pubDate></item></channel></rss>