<?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[[SOLVED] How to detect QStackedWidget focus?]]></title><description><![CDATA[<p dir="auto">I have a QStackedWidget and I need to know when it receives focus (in other words, when any of its child widgets receives focus). I've tried installing an event filter onto it:</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bool">@<bdi>bool</bdi></a> CMainWindow::eventFilter(QEvent * e, QObject* o)<br />
{<br />
if (e &amp;&amp; e-&gt;type() == QEvent::FocusIn)<br />
{<br />
// FocusIn detected - do stuff<br />
}<br />
return QMainWindow::eventFilter(e, o);<br />
}@</p>
<p dir="auto">Note that I don't even check the sender object, and I still never get the FocusIn event. How can I detect this event?</p>
]]></description><link>https://forum.qt.io/topic/46636/solved-how-to-detect-qstackedwidget-focus</link><generator>RSS for Node</generator><lastBuildDate>Sat, 16 May 2026 22:01:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/46636.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 03 Oct 2014 12:07:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] How to detect QStackedWidget focus? on Sat, 04 Oct 2014 17:46:43 GMT]]></title><description><![CDATA[<p dir="auto">Thank you Chris, that's exactly what I was looking for!</p>
]]></description><link>https://forum.qt.io/post/246230</link><guid isPermaLink="true">https://forum.qt.io/post/246230</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Sat, 04 Oct 2014 17:46:43 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] How to detect QStackedWidget focus? on Fri, 03 Oct 2014 13:56:38 GMT]]></title><description><![CDATA[<p dir="auto">Well focus events don't usually bubble up so there's no direct way to capture them in a parent (for the most part).</p>
<p dir="auto">What you can do is, instead of filtering events, connect to the "QApplication::focusChanged":<a href="http://qt-project.org/doc/qt-5/qapplication.html#focusChanged" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qapplication.html#focusChanged</a> signal and in the related slot check if the new widget with focus is a child of the relevant stacked widget page. You can do that by calling contains() on a findChildren() result (like in the example I gave earlier).</p>
]]></description><link>https://forum.qt.io/post/246138</link><guid isPermaLink="true">https://forum.qt.io/post/246138</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Fri, 03 Oct 2014 13:56:38 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] How to detect QStackedWidget focus? on Fri, 03 Oct 2014 13:35:00 GMT]]></title><description><![CDATA[<p dir="auto">That is not a solution for me because I will dynamically add and remove widgets to and from StackedWidget. Installing event filter for each would require overriding the QStackedWidget and is pretty tedious, if at all possible. Is there no easier way?</p>
]]></description><link>https://forum.qt.io/post/246136</link><guid isPermaLink="true">https://forum.qt.io/post/246136</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Fri, 03 Oct 2014 13:35:00 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] How to detect QStackedWidget focus? on Fri, 03 Oct 2014 13:25:09 GMT]]></title><description><![CDATA[<p dir="auto">StackedWidget is not a user interactive control so it doesn't have a focus event. What you can do is to install the event filter on each child widget of it and filter for that, eg.<br />
@<br />
auto widgetIndex = ...<br />
auto cldrn = stacWid-&gt;widget(widgetIndex)-&gt;findChildren&lt;QWidget*&gt;();<br />
for(auto obj : cldrn)<br />
obj-&gt;installEventFilter(whatever);<br />
@</p>
<p dir="auto"><em>EDIT:</em> You can get a focus on the stacked widget by setting a focus policy of the relevant page frames to StrongFocus, but it will only gain focus via keybord, not mouse, and not when children gain focus, so my previous advice holds.</p>
]]></description><link>https://forum.qt.io/post/246135</link><guid isPermaLink="true">https://forum.qt.io/post/246135</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Fri, 03 Oct 2014 13:25:09 GMT</pubDate></item></channel></rss>