<?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[QTreeView: dragging and dropping items with left mouse button?]]></title><description><![CDATA[<p dir="auto">I'm unable to get drag and drop working using the left mouse button in a QTreeView. It does work with RMB. But with the LMB the view just selects multiple items that I drag across.</p>
<p dir="auto">Here are my tree view properties:<br />
<a href="http://i.stack.imgur.com/NT07q.png" target="_blank" rel="noopener noreferrer nofollow ugc">http://i.stack.imgur.com/NT07q.png</a></p>
<p dir="auto">So, how can I get dragging with a left mouse button to work?</p>
<p dir="auto">P. S. I have confirmed that with the settings depicted above the "Editable tree model" example demonstrates exactly the same behavior.</p>
]]></description><link>https://forum.qt.io/topic/54760/qtreeview-dragging-and-dropping-items-with-left-mouse-button</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 10:26:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/54760.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 31 May 2015 14:01:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Thu, 04 Jun 2015 06:26:06 GMT]]></title><description><![CDATA[<p dir="auto">So, there's no <em>simple</em> way to start dragging a specific item?</p>
]]></description><link>https://forum.qt.io/post/276658</link><guid isPermaLink="true">https://forum.qt.io/post/276658</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Thu, 04 Jun 2015 06:26:06 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Wed, 03 Jun 2015 05:00:22 GMT]]></title><description><![CDATA[<p dir="auto">This is a file manager application, this TreeView is the main file list view. Selection on click really looks horrible, and it's redundant - that's what the cursor is for (the thin dotted frame around an item). And not only that, but this selection upon click breaks other selection management operations.</p>
]]></description><link>https://forum.qt.io/post/276483</link><guid isPermaLink="true">https://forum.qt.io/post/276483</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Wed, 03 Jun 2015 05:00:22 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Tue, 02 Jun 2015 22:32:19 GMT]]></title><description><![CDATA[<p dir="auto">You would need to re-implement it yourself but why do you do that clear in the pressEvent ?</p>
]]></description><link>https://forum.qt.io/post/276451</link><guid isPermaLink="true">https://forum.qt.io/post/276451</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 02 Jun 2015 22:32:19 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Tue, 02 Jun 2015 04:50:07 GMT]]></title><description><![CDATA[<p dir="auto">I see!<br />
Can I somehow start drag manually in the <code>mouseMove</code> event?</p>
]]></description><link>https://forum.qt.io/post/276333</link><guid isPermaLink="true">https://forum.qt.io/post/276333</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Tue, 02 Jun 2015 04:50:07 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Mon, 01 Jun 2015 23:09:20 GMT]]></title><description><![CDATA[<p dir="auto">To start a drag operation you need to select an index. What you do is that you clear that selection right after it happened so there's nothing to drag anymore.</p>
]]></description><link>https://forum.qt.io/post/276316</link><guid isPermaLink="true">https://forum.qt.io/post/276316</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 01 Jun 2015 23:09:20 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Mon, 01 Jun 2015 09:59:57 GMT]]></title><description><![CDATA[<p dir="auto">Found what's breaking the drag and drop. It's my code that deselects an item that was single-clicked:</p>
<pre><code>void CFileListView::mousePressEvent(QMouseEvent *e)`
{
	const QModelIndex itemClicked = indexAt(e-&gt;pos());

    QTreeView::mousePressEvent(e);

    if (e-&gt;button() == Qt::LeftButton &amp;&amp; itemClicked.isValid() &amp;&amp; e-&gt;modifiers() == Qt::NoModifier)
	    selectionModel()-&gt;clearSelection();
}
</code></pre>
<p dir="auto">If I comment out the <code>clearSelection</code> call, drag and drop starts working. With <code>clearSelection</code> it's as if D&amp;D is not enabled.<br />
No idea what exactly is happening or how to fix this.</p>
]]></description><link>https://forum.qt.io/post/276209</link><guid isPermaLink="true">https://forum.qt.io/post/276209</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Mon, 01 Jun 2015 09:59:57 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Sun, 31 May 2015 22:12:19 GMT]]></title><description><![CDATA[<p dir="auto">That's not enough. The example also provides a custom model. The model should also provide the Qt::ItemIsDragEnabled item flag as needed if you want your items to be draggable</p>
]]></description><link>https://forum.qt.io/post/276156</link><guid isPermaLink="true">https://forum.qt.io/post/276156</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 31 May 2015 22:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Sun, 31 May 2015 21:11:01 GMT]]></title><description><![CDATA[<p dir="auto">That's why I added <strong>"with the settings depicted above"</strong>. I open the example, change those properties and observe the undesired behavior.</p>
]]></description><link>https://forum.qt.io/post/276146</link><guid isPermaLink="true">https://forum.qt.io/post/276146</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Sun, 31 May 2015 21:11:01 GMT</pubDate></item><item><title><![CDATA[Reply to QTreeView: dragging and dropping items with left mouse button? on Sun, 31 May 2015 20:48:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">AFAIK, this example doesn't activate the drag and drop feature of QTreeView.</p>
<p dir="auto">You have the documentation <a href="http://doc.qt.io/qt-5/model-view-programming.html" target="_blank" rel="noopener noreferrer nofollow ugc">here</a></p>
]]></description><link>https://forum.qt.io/post/276144</link><guid isPermaLink="true">https://forum.qt.io/post/276144</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 31 May 2015 20:48:54 GMT</pubDate></item></channel></rss>