<?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[QItemDelegate with multiple QWidgets inside - Focus problem]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have a QStyledItemDelegate with a custom pain event that holds several other widgets. Now when the delegate is clicked the focus jumps to the delegate. However it should be at the underlying widget that was clicked on.<br />
If there is only one widget I can achieve the desired behaviour by delegateWidget-&gt;setFocusProxy(the_editor_widget);<br />
However this naturally only works for one widget. Is there some method to "forward" the click to the underlying widget?</p>
]]></description><link>https://forum.qt.io/topic/98685/qitemdelegate-with-multiple-qwidgets-inside-focus-problem</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 16:33:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/98685.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 18 Jan 2019 16:59:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QItemDelegate with multiple QWidgets inside - Focus problem on Sun, 20 Jan 2019 18:48:16 GMT]]></title><description><![CDATA[<p dir="auto">I had similar problem and went through couple of different solutions. My case was specific in the sense that I only wanted the edit to start via mouse press, not other methods (i.e. enter or tab). In that specific case I ended with the following:</p>
<p dir="auto">Blocked all edit triggers by setting <a href="http://doc.qt.io/qt-5/qabstractitemview.html#editTriggers-prop" target="_blank" rel="noopener noreferrer nofollow ugc">editTriggers</a> to <code>NoEditTriggers</code>.<br />
Implemented <a href="http://doc.qt.io/qt-5/qabstractitemdelegate.html#editorEvent" target="_blank" rel="noopener noreferrer nofollow ugc">editorEvent()</a> in the delegate to recognize a mouse press and calling <code>edit()</code> manually.<br />
In the created widget I implemented <code>showEvent()</code>. In it I check if it's the first show event or not. If it's the first I synthesize a fake mouse release event followed by a mouse press event and send them to the app via <a href="http://doc.qt.io/qt-5/qcoreapplication.html#sendEvent" target="_blank" rel="noopener noreferrer nofollow ugc">QApplication::sendEvent()</a>. Some attention was needed to make sure the fake events are with the same mouse buttons and other event options, otherwise you can easily confuse the internals of the view.</p>
<p dir="auto">This way Qt does all the work to figure out which widget should get the focus and mouse press, how to route it through the item view etc. You can probably extend this to other trigger methods. You would just need to tell the widget somehow about which trigger method was used and act accordingly in the <code>showEvent()</code> e.g. set focus on the "first" widget when it's via tab key and so forth.</p>
]]></description><link>https://forum.qt.io/post/505972</link><guid isPermaLink="true">https://forum.qt.io/post/505972</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 20 Jan 2019 18:48:16 GMT</pubDate></item><item><title><![CDATA[Reply to QItemDelegate with multiple QWidgets inside - Focus problem on Sun, 20 Jan 2019 17:41:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a>: Thanks for the hint, however <code>qApp-&gt;widgetAt(QCursor::pos());</code> returns the viewport of the TreeView (qt_scollarea_viewport) instead of the widget inside the delegate.</p>
]]></description><link>https://forum.qt.io/post/505964</link><guid isPermaLink="true">https://forum.qt.io/post/505964</guid><dc:creator><![CDATA[gde23]]></dc:creator><pubDate>Sun, 20 Jan 2019 17:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to QItemDelegate with multiple QWidgets inside - Focus problem on Fri, 18 Jan 2019 20:53:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">One possibility could be to use <a href="http://doc.qt.io/qt-5/qapplication.html#widgetAt" target="_blank" rel="noopener noreferrer nofollow ugc">QApplication::widgetAt</a> in your editor showEvent and check there which widget is under the cursor to give it the focus.</p>
]]></description><link>https://forum.qt.io/post/505748</link><guid isPermaLink="true">https://forum.qt.io/post/505748</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 18 Jan 2019 20:53:25 GMT</pubDate></item><item><title><![CDATA[Reply to QItemDelegate with multiple QWidgets inside - Focus problem on Fri, 18 Jan 2019 18:13:10 GMT]]></title><description><![CDATA[<p dir="auto">If eventFilters are the solution, then maybe.<br />
But I do not know how exactly to solve it with event filters.</p>
<p dir="auto">The <code>QTreeView::mousePressEvent()</code><br />
triggers <code>QStyledItemDelegate::createEditor(); and QStyledItemDelegate::setEditorData();</code>.<br />
However, now the click needs to kind of be repeated on the created editor Widget.</p>
]]></description><link>https://forum.qt.io/post/505725</link><guid isPermaLink="true">https://forum.qt.io/post/505725</guid><dc:creator><![CDATA[gde23]]></dc:creator><pubDate>Fri, 18 Jan 2019 18:13:10 GMT</pubDate></item><item><title><![CDATA[Reply to QItemDelegate with multiple QWidgets inside - Focus problem on Fri, 18 Jan 2019 17:37:07 GMT]]></title><description><![CDATA[<p dir="auto">Are you looking for event filters ?</p>
]]></description><link>https://forum.qt.io/post/505719</link><guid isPermaLink="true">https://forum.qt.io/post/505719</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Fri, 18 Jan 2019 17:37:07 GMT</pubDate></item></channel></rss>