<?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[After clearing selection, the last selected item is still selected]]></title><description><![CDATA[<p dir="auto">I have a tree view.</p>
<p dir="auto">I needed some cleverness in what was selected when the user clicked on various parts of it.</p>
<p dir="auto">There is a way to click in the treeview that causes the selection model to be cleared. That is, the following code is called:</p>
<p dir="auto"><code>selectionModel-&gt;clearSelection();</code></p>
<p dir="auto">Immediately after this, the row that was previously highlighted with a blue background no longer has a blue background. However, it still has a dotted outline, and when the selection is fetched</p>
<p dir="auto"><code>model-&gt;selectedRows()</code></p>
<p dir="auto">that row is still selected. Where my code is currently doing this:<br />
<code>selectionModel-&gt;clearSelection();</code><br />
I want to actually clear the selection. I want there to be nothing selected. I'm sure that's what clearSelection is meant to do, so what's with the dotted outline and why is that row still selected?</p>
]]></description><link>https://forum.qt.io/topic/42651/after-clearing-selection-the-last-selected-item-is-still-selected</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 02:03:47 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42651.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Jun 2014 12:25:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to After clearing selection, the last selected item is still selected on Thu, 07 Dec 2017 10:14:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/laurab">@<bdi>LauraB</bdi></a> said in <a href="/post/430388">After clearing selection, the last selected item is still selected</a>:</p>
<blockquote>
<p dir="auto">when you set an item as current you also set it as selected</p>
</blockquote>
<p dir="auto">Not necessarily.</p>
<ol>
<li>select item 1 (selection = {item 1}, currentIndex = item 1)</li>
<li>ctrl+select item 2 (selection = {item 1,item 2}, currentIndex = item 2)</li>
<li>ctrl+deselect item 1 (selection = {item 2}, currentIndex = item 1)</li>
</ol>
]]></description><link>https://forum.qt.io/post/430389</link><guid isPermaLink="true">https://forum.qt.io/post/430389</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Thu, 07 Dec 2017 10:14:22 GMT</pubDate></item><item><title><![CDATA[Reply to After clearing selection, the last selected item is still selected on Thu, 07 Dec 2017 10:05:45 GMT]]></title><description><![CDATA[<p dir="auto">This reply happens a little late, I know, but I stumbled upon the same problematic today and I think I figured it out. I guess other people can also have the same issue, so I allow myself to reply to this very old topic :</p>
<p dir="auto">I understood it all after reading this : <a href="http://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/model-view-programming.html#handling-selections-in-item-views</a></p>
<p dir="auto">To summarize, regarding our issue which is even if we clear selection we still have a dotted outline on the item, it's because "selected" item and "current" item are two differents states in Qt.</p>
<p dir="auto">Unless the selection mode on your model/view is NoSelection, when you set an item as current you also set it as selected (by clicking on it or by calling <em>setCurrentIndex()</em> ).<br />
However, after <em>clearSelection()</em>, you only set the "selected" state to false, but this item is still your "current" item.</p>
<p dir="auto">The solution I found for this is to call <em>setCurrentIndex()</em> and pass to it an invalid index.</p>
<p dir="auto">Hope this helps for people who had the same problem.</p>
<p dir="auto">Regards,</p>
<p dir="auto">Laura B.</p>
]]></description><link>https://forum.qt.io/post/430388</link><guid isPermaLink="true">https://forum.qt.io/post/430388</guid><dc:creator><![CDATA[LauraB]]></dc:creator><pubDate>Thu, 07 Dec 2017 10:05:45 GMT</pubDate></item></channel></rss>