<?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[Deselect *visually* at start of program]]></title><description><![CDATA[<p dir="auto">I have a couple of <code>QTreeWidget</code>s in my UI, which I fill when I init my MainWindow (Creation Process: Construct -&gt; Init -&gt; Show) then I always get a ghost selection in all TWs.</p>
<p dir="auto">When I fill the data into the TWs, I surround it with:</p>
<pre><code>ui-&gt;itemList-&gt;clear(); 
ui-&gt;itemList-&gt;clearSelection();
ui-&gt;itemList-&gt;blockSignals(true);
// Fill data
ui-&gt;itemList-&gt;blockSignals(false);
</code></pre>
<p dir="auto">(<code>itemList</code> = one of my TWs)</p>
<p dir="auto">While <code>clearSelection</code> does clear the selection for the code (<code>ui-&gt;itemTree-&gt;selectedItems().isEmpty()</code>) it does not do that visually<img src="https://ddgobkiprc33d.cloudfront.net/5534f885-cad5-405a-a85e-f117edabea1c.png" alt="7928c500-8322-416a-bc08-b46e621ad0fe-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">The item <em>looks</em> selected, but isn't according to the code</p>
<pre><code>bool noItemSel = ui-&gt;itemList-&gt;selectedItems().isEmpty();
</code></pre>
<p dir="auto">This variable gets used to enable/disable certain buttons which should only work if an item is selected:</p>
<pre><code>    ui-&gt;pbItemAdd-&gt;setDisabled(noTreeRights);
    ui-&gt;pbItemEdit-&gt;setDisabled(noItemSel || noTreeRights);
    ui-&gt;pbItemDelete-&gt;setDisabled(noItemSel || noTreeRights);
</code></pre>
<p dir="auto">these buttons, shown here<br />
<img src="https://ddgobkiprc33d.cloudfront.net/f2d25cfc-7c9b-4583-b9cb-d6f150cf52ef.png" alt="6d1be532-9af5-47bd-9d3a-4b5a20ada45a-image.png" class=" img-fluid img-markdown" /><br />
get disabled, <code>noTreeRights</code> is false, as seen by the add button, so that one doesnt cause the issue of disabling. Theres a lot of other loading done when someone selects an Item, so I'd rather keep the tree widget unselected than selecting the first item</p>
<p dir="auto">So how do I remove that visual selection?</p>
]]></description><link>https://forum.qt.io/topic/146069/deselect-visually-at-start-of-program</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 01:50:34 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/146069.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Jun 2023 11:15:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 16:39:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gklc">@<bdi>GKLC</bdi></a><br />
By now I suggest you produce a 20-odd line standalone minimal example.  Reduce to absolute least which produces behaviour.  May not apply to you, but 50% of the time we ask for this the OP discovers the issue.  Try for yourself just starting anew from a <code>QTreeWidget</code>.</p>
]]></description><link>https://forum.qt.io/post/762895</link><guid isPermaLink="true">https://forum.qt.io/post/762895</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 28 Jun 2023 16:39:23 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 12:48:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/axel-spoerl">@<bdi>Axel-Spoerl</bdi></a> I've tried setting the current item to a nullptr, which didn't help</p>
<p dir="auto">I do need to be <em>able</em> to set a selection (<code>SingleSelection</code> specifically), at the start of the program however, I don't want anything selected, as it makes it confusing for users.</p>
<p dir="auto">Its also definitely a selection if the current item only has that frame, that is, if the selected item is the highlighted blue item shown in the picture</p>
]]></description><link>https://forum.qt.io/post/762891</link><guid isPermaLink="true">https://forum.qt.io/post/762891</guid><dc:creator><![CDATA[GKLC]]></dc:creator><pubDate>Wed, 28 Jun 2023 12:48:24 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 12:39:38 GMT]]></title><description><![CDATA[<p dir="auto">First of all, as @J-Hilk pointed out, disable selections by<br />
<code>myTreeview-&gt;setSelectionMode(QAbstractItemView::NoSelection);</code></p>
<p dir="auto">Nothing can be selected from now on.<br />
What may look a bit like a selection is the <code>currentItem</code>.<br />
That should not be highlighted, unless the tree widget has focus.<br />
It is usually rendered with a visible frame, indicating that the frame can be moved with the up/down keys and the item can be expanded/collapsed with the left/right keys.</p>
]]></description><link>https://forum.qt.io/post/762889</link><guid isPermaLink="true">https://forum.qt.io/post/762889</guid><dc:creator><![CDATA[Axel Spoerl]]></dc:creator><pubDate>Wed, 28 Jun 2023 12:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 12:37:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> First 3 things do nothing, whether all together or singularly, the first item still is highlighted but not selected, which seems to confirm the 4th item that you suggested. The first item gets highlighted, though not selected (debugger confirms)</p>
]]></description><link>https://forum.qt.io/post/762887</link><guid isPermaLink="true">https://forum.qt.io/post/762887</guid><dc:creator><![CDATA[GKLC]]></dc:creator><pubDate>Wed, 28 Jun 2023 12:37:02 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 12:23:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gklc">@<bdi>GKLC</bdi></a><br />
While you wait for an answer, what about a bit more detective work?</p>
<ul>
<li>Move the <code>clearSelection()</code> to <em>after</em> the <code>blockSignals()</code> and data filling?</li>
<li>Can you temporarily comment out the <code>blockSignals()</code>, does that change behaviour?</li>
<li>Try selecting a <em>different</em> item in code.  (Note: I think that requires changing the <em>selection</em>, not the <em>currrent</em> item.)  Does the blue item move?</li>
<li>Is there any chance the first item in the list gets auto-/re-selected when first shown, independent of your code setting (I don't know)?</li>
<li>Try moving any selecting or deselecting code into a slot executed on a <code>QTimer::singleShot()</code> with a delay of 0 or small to execute after your filling code.  Does that work?</li>
</ul>
]]></description><link>https://forum.qt.io/post/762885</link><guid isPermaLink="true">https://forum.qt.io/post/762885</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 28 Jun 2023 12:23:26 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 12:03:46 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk I did <code>ui-&gt;itemList-&gt;setCurrentItem(nullptr)</code> now, and it still is highlighted</p>
]]></description><link>https://forum.qt.io/post/762881</link><guid isPermaLink="true">https://forum.qt.io/post/762881</guid><dc:creator><![CDATA[GKLC]]></dc:creator><pubDate>Wed, 28 Jun 2023 12:03:46 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 11:59:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gklc">@<bdi>GKLC</bdi></a> that item is probably the <a href="https://doc.qt.io/qt-6/qtreewidget.html#setCurrentItem" target="_blank" rel="noopener noreferrer nofollow ugc">"currentItem"</a><br />
and since your selection mode is not  <code>NoSelection</code> the item is also "selected" aka highlighted</p>
]]></description><link>https://forum.qt.io/post/762879</link><guid isPermaLink="true">https://forum.qt.io/post/762879</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Wed, 28 Jun 2023 11:59:17 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 11:50:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/axel-spoerl">@<bdi>Axel-Spoerl</bdi></a> I added the obvious question now.</p>
]]></description><link>https://forum.qt.io/post/762875</link><guid isPermaLink="true">https://forum.qt.io/post/762875</guid><dc:creator><![CDATA[GKLC]]></dc:creator><pubDate>Wed, 28 Jun 2023 11:50:49 GMT</pubDate></item><item><title><![CDATA[Reply to Deselect *visually* at start of program on Wed, 28 Jun 2023 11:32:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gklc">@<bdi>GKLC</bdi></a><br />
Thanks. Am I overlooking something? I don’t find a question in your post!</p>
]]></description><link>https://forum.qt.io/post/762871</link><guid isPermaLink="true">https://forum.qt.io/post/762871</guid><dc:creator><![CDATA[Axel Spoerl]]></dc:creator><pubDate>Wed, 28 Jun 2023 11:32:44 GMT</pubDate></item></channel></rss>