<?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[Is grabMouse undone when a top-level QWidget terminates?]]></title><description><![CDATA[<p dir="auto">I have a large and complex application ported to Qt 5.7,  where Qt problems are usually not reproducible in a small and simple test application.</p>
<p dir="auto">I believe that I found a case of grabMouse not being undone when a top-level QWidget terminates. The result is that mouse interaction becomes impossible in the whole application and only the keyboard works. It is possible that the problem only occurs when the QWidget is closed via the Close button (the X button on top-right of the border).</p>
<p dir="auto">I found the problem because in one test run, and one only, I got an error message for releaseMouse saying it is impossible for an invisible window. I theorize that when the X button is pressed, the window becomes invisible and the releaseMouse is ignored, so the application loses the usage of the mouse in favor of a no-longer existing widget.</p>
<p dir="auto">Abolishing all calls of grabMouse and releaseMouse in the application solved the problem.</p>
<p dir="auto">I do not post a bug report, since the details are too vague. But maybe some developer could think about it.</p>
]]></description><link>https://forum.qt.io/topic/69753/is-grabmouse-undone-when-a-top-level-qwidget-terminates</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 23:39:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/69753.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 29 Jul 2016 09:42:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 16:42:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a></p>
<p dir="auto">The case I worry about is that of the mouse down and up events. A problem can occur if another window is activated between these two events, especially during a drag operation, meaning that the mouse-up event is received by that other window, so the window to receive the mouse-down event may never fully terminate its handling.</p>
<p dir="auto">This case is rare enough, but potentially destructive to the UI. Do you know if this can happen in Qt when not using manual grab ?</p>
]]></description><link>https://forum.qt.io/post/339950</link><guid isPermaLink="true">https://forum.qt.io/post/339950</guid><dc:creator><![CDATA[Harry123]]></dc:creator><pubDate>Fri, 29 Jul 2016 16:42:05 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 13:52:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/harry123">@<bdi>Harry123</bdi></a> said:</p>
<blockquote>
<p dir="auto">My understanding is that grab/release in Qt are frowned upon</p>
</blockquote>
<p dir="auto">Somewhat, albeit sometimes they are needed, hence the mouse grabbing is exposed through the public API.</p>
<blockquote>
<p dir="auto">the underlying mouse logic seems solid enough so they are not really required</p>
</blockquote>
<p dir="auto">Yes, most of the time.</p>
<blockquote>
<p dir="auto">I'm not sure that a simple test program could duplicate this condition.</p>
</blockquote>
<p dir="auto">Well, the thing is this:<br />
Even if you post this as a bugreport, you'd want to have some collaboration for someone to pick it up. What I mean is that if you don't provide any means of reproduction (i.e. a test case application) and your description is vague or the bug is very complex/hard to reproduce it may stay in the tracker for a long, long time ... attaching screenshots also might help the developers to triage and ultimately fix the bug.</p>
<p dir="auto">Kind regards.</p>
]]></description><link>https://forum.qt.io/post/339924</link><guid isPermaLink="true">https://forum.qt.io/post/339924</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Fri, 29 Jul 2016 13:52:55 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 13:27:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a></p>
<p dir="auto">It might be that the close button is essential and its handler should release the grab.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a></p>
<p dir="auto">I see I was right not to post a bug report, since the case is too vague.</p>
<p dir="auto">My understanding is that grab/release in Qt are frowned upon, and my (limited) experience now is that the underlying mouse logic seems solid enough so they are not really required.</p>
<p dir="auto">All I can say is that the application, while using Windows API, did release correctly all its grabs. However, under Qt the same application managed to place itself in a situation where the last release did not work and a virtual grab remained in effect. I'm not sure that a simple test program could duplicate this condition.</p>
]]></description><link>https://forum.qt.io/post/339920</link><guid isPermaLink="true">https://forum.qt.io/post/339920</guid><dc:creator><![CDATA[Harry123]]></dc:creator><pubDate>Fri, 29 Jul 2016 13:27:28 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 12:51:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/harry123">@<bdi>Harry123</bdi></a></p>
<blockquote>
<p dir="auto">I theorize that when the X button is pressed, the window becomes invisible and the releaseMouse is ignored</p>
</blockquote>
<p dir="auto">Doubtful. You have to match the <em>grabs</em> with <em>releases</em>, possibly you have a codepath somewhere that doesn't go through the <em>release</em>. Also if I recall correctly, you need to call <em>release</em> the exact number of times you call <em>grab</em>.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a></p>
<blockquote>
<p dir="auto">If you new a Widget, let it grab and then delete it, the mouse is restored.</p>
</blockquote>
<p dir="auto">This is platform specific and ultimately will depend on the window manager. Usually the window manager will release the <em>grab</em> when the receiving native surface handle is destroyed.</p>
<blockquote>
<p dir="auto">Hide does not release it.</p>
</blockquote>
<p dir="auto">Nor should it. Grabbing the mouse is quite an exclusive operation.</p>
]]></description><link>https://forum.qt.io/post/339909</link><guid isPermaLink="true">https://forum.qt.io/post/339909</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Fri, 29 Jul 2016 12:51:46 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 10:08:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/harry123">@<bdi>Harry123</bdi></a></p>
<p dir="auto">hi , just made small test.</p>
<p dir="auto">If you new a Widget, let it grab and then delete it, the mouse is restored.<br />
So seems that delete will release.</p>
<p dir="auto">so I guess you hide a window while it has grab?<br />
Ill test that in a moment.</p>
<p dir="auto">update:<br />
Hide does not release it.</p>
]]></description><link>https://forum.qt.io/post/339886</link><guid isPermaLink="true">https://forum.qt.io/post/339886</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 29 Jul 2016 10:08:46 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 10:05:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a></p>
<p dir="auto">Agreed, but in this one case there might be a gotcha.</p>
]]></description><link>https://forum.qt.io/post/339885</link><guid isPermaLink="true">https://forum.qt.io/post/339885</guid><dc:creator><![CDATA[Harry123]]></dc:creator><pubDate>Fri, 29 Jul 2016 10:05:16 GMT</pubDate></item><item><title><![CDATA[Reply to Is grabMouse undone when a top-level QWidget terminates? on Fri, 29 Jul 2016 10:01:45 GMT]]></title><description><![CDATA[<p dir="auto">hi<br />
As far as I know you must match the calls yourself.<br />
Not tested lately but when I used it,<br />
i had the impression that only when application is<br />
closed mouse is fully released.</p>
<p dir="auto">the doc states</p>
<p dir="auto">Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging.</p>
<p dir="auto">so I would not count on auto clean up.</p>
]]></description><link>https://forum.qt.io/post/339884</link><guid isPermaLink="true">https://forum.qt.io/post/339884</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 29 Jul 2016 10:01:45 GMT</pubDate></item></channel></rss>