<?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[Drop event not generated after an accepted Drag Enter event]]></title><description><![CDATA[<p dir="auto">I'm trying to create a tiny helper class that would facilitate processing drop events for any widget. Here's the definition, it should be pretty clear what the idea is:</p>
<pre><code>FileDropHandler::FileDropHandler(QWidget* widget, const std::function&lt;void (const FileNamesContainer&amp;)&gt;&amp; handler) :
	QObject(widget),
	_handler(handler)
{
	assert(widget);
	assert(handler);

	widget-&gt;setAcceptDrops(true);
	widget-&gt;installEventFilter(this);
}

bool FileDropHandler::eventFilter(QObject* /*watched*/, QEvent* event)
{
	if (event-&gt;type() == QEvent::DragEnter)
	{
		auto * e = static_cast&lt;QDragEnterEvent*&gt;(event);
		if (e-&gt;mimeData()-&gt;hasUrls())
			e-&gt;acceptProposedAction();
	}
	else if (event-&gt;type() == QEvent::Drop)
	{
		auto * e = static_cast&lt;QDropEvent*&gt;(event);

		FileNamesContainer filePaths;
		for (const QUrl&amp; url: e-&gt;mimeData()-&gt;urls())
			filePaths.emplace_back(url.toLocalFile());

		_handler(filePaths);
	}

	return false;
}
</code></pre>
<p dir="auto"><code>FileDropHandler</code> is, of course, a subclass of <code>QObject</code>. And I'm instantiating it for a certain <code>QTextEdit</code>. Problem: <code>DragEnter</code> event is processed and <code>acceptProposedAction</code> is executed, but the <code>Drop</code> event does not follow. What did I miss?</p>
]]></description><link>https://forum.qt.io/topic/77083/drop-event-not-generated-after-an-accepted-drag-enter-event</link><generator>RSS for Node</generator><lastBuildDate>Mon, 04 May 2026 22:03:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/77083.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 10 Mar 2017 11:21:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Drop event not generated after an accepted Drag Enter event on Fri, 10 Mar 2017 22:37:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">AFAIK, <code>e-accept()</code> just tells that the system want the event. Returning true from eventFilter means that the event has been handled and handling should stop there.</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/381366</link><guid isPermaLink="true">https://forum.qt.io/post/381366</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 10 Mar 2017 22:37:22 GMT</pubDate></item><item><title><![CDATA[Reply to Drop event not generated after an accepted Drag Enter event on Fri, 10 Mar 2017 21:32:14 GMT]]></title><description><![CDATA[<p dir="auto"><code>return true</code> after <code>e-&gt;acceptProposedAction()</code> fixed it. And I get it. What I don't get is this: I have tried <code>e-&gt;accept()</code> before posting this question, and it did not help. Can someone please explain?</p>
]]></description><link>https://forum.qt.io/post/381351</link><guid isPermaLink="true">https://forum.qt.io/post/381351</guid><dc:creator><![CDATA[Violet Giraffe]]></dc:creator><pubDate>Fri, 10 Mar 2017 21:32:14 GMT</pubDate></item></channel></rss>