<?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[Dragging out to non-Qt desktop]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I’m working on dragging and dropping capability in my desktop app, which consists of multiple QWidget.<br />
D&amp;D works OK if it’s internal movement where the drop receiver is another QWidget.<br />
My question is how can I achieve the same functionality between the desktop app and non Qt app such as Window desktop where no qt app exists.<br />
How and where can I handle the dropEvent outside of Qt?</p>
<p dir="auto">Many thanks in advance for your help.<br />
Sat</p>
]]></description><link>https://forum.qt.io/topic/84861/dragging-out-to-non-qt-desktop</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 18:59:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/84861.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Nov 2017 22:15:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 10:45:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said in <a href="/post/425286">Dragging out to non-Qt desktop</a>:</p>
<blockquote>
<p dir="auto">Would it be possible to get the test code ?</p>
</blockquote>
<p dir="auto">thats actually all the code (despite the obvious header file).</p>
<p dir="auto">All i did additionally for testing was this:</p>
<pre><code>void MainWindow::mousePressEvent(QMouseEvent *event)
{
    event-&gt;accept();

    MimeData* mimeData = new MimeData;

    QDrag drag( this );
        drag.setMimeData(mimeData);
    drag.exec(Qt::CopyAction);
}
</code></pre>
<p dir="auto">the mime type is <code>text/uri-list</code>, so a list does make sense. It also makes sense to copy multiple files at once to a folder in the filesystem explorer.<br />
I have no idea why it's not working. Would need to debug into Qt source code to make sure.</p>
]]></description><link>https://forum.qt.io/post/425308</link><guid isPermaLink="true">https://forum.qt.io/post/425308</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 10 Nov 2017 10:45:02 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 09:22:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a></p>
<p dir="auto">Good work.<br />
Ehh so it likes only root of tmp dir ?? odd<br />
2: that is a bit odd but i guess it was only ment for 1 file then.</p>
<p dir="auto">Would it be possible to get the test code ?<br />
Want to see if win 10 likes it also :)</p>
<p dir="auto">This is nicer than the platform bound i found :) \o/</p>
]]></description><link>https://forum.qt.io/post/425286</link><guid isPermaLink="true">https://forum.qt.io/post/425286</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Nov 2017 09:22:11 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 10:43:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
the following (<strong>unoptimized code</strong>) works (Qt 5.9, Windows 7):</p>
<pre><code>MimeData::MimeData()
    : QMimeData()
{
    QString filePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) % QDir::separator() % "Gaspar Website.url";
    m_File = new QFile( filePath, this );
}

MimeData::~MimeData()
{
    if( m_File &amp;&amp; m_File-&gt;isOpen() )
        m_File-&gt;close();
}

QStringList MimeData::formats() const
{
    return QMimeData::formats() &lt;&lt; QLatin1String("text/uri-list");
}

QVariant MimeData::retrieveData(const QString &amp;mimeType, QVariant::Type type) const
{
    if( mimeType == QStringLiteral("text/uri-list") )
    {
        // since this method may be called multiple during a single drag it's not necessary to also write to the file multiple times -&gt; needs optimization
        if( m_File-&gt;open(QFile::WriteOnly) )
        {
            m_File-&gt;write( QByteArray("[InternetShortcut]\r\nURL=http://www.gaspar.net") );
            m_File-&gt;close();
        }

        return QVariant::fromValue&lt;QUrl&gt;( QUrl::fromLocalFile(QFileInfo(*m_File).absoluteFilePath()) );
    }
    else
        return QMimeData::retrieveData(mimeType, type);
}
</code></pre>
<p dir="auto">Although it seems there are some caveats:</p>
<ol>
<li>it stopped working when i set the path of the temp file into a subfolder in the temp-dir ... <strong>o.O</strong></li>
<li>the <code>retrieveData()</code> always requests the data with the type <code>QVariant::QVariantList</code>. But still it only works when i return a QUrl (not a QList) packed into the variant data.</li>
</ol>
<p dir="auto">Very strange.</p>
]]></description><link>https://forum.qt.io/post/425281</link><guid isPermaLink="true">https://forum.qt.io/post/425281</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 10 Nov 2017 10:43:45 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 08:22:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a></p>
<p dir="auto">Super. Maybe i just do it wrong.<br />
I drag the export Button out from window. It show red stop sign.</p>
]]></description><link>https://forum.qt.io/post/425270</link><guid isPermaLink="true">https://forum.qt.io/post/425270</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Nov 2017 08:22:43 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 08:18:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
yes, but it's a while ago. I will give it a try.</p>
]]></description><link>https://forum.qt.io/post/425268</link><guid isPermaLink="true">https://forum.qt.io/post/425268</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 10 Nov 2017 08:18:50 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 08:14:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a></p>
<p dir="auto">Did you try delayed encoding sample ?</p>
<p dir="auto">The sample will not work for me on win 7 or win 10.<br />
Tried 2 pc.  Desktop/explorer wont accept.</p>
<p dir="auto">So i wonder if issue with my pcs or just dont work like that in newer Windows.</p>
]]></description><link>https://forum.qt.io/post/425266</link><guid isPermaLink="true">https://forum.qt.io/post/425266</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 10 Nov 2017 08:14:39 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Fri, 10 Nov 2017 08:05:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Just a note: File drags to desktop can also be achieved using Qt classes only:</p>
<ol>
<li>start a drag containing all the needed mime-types</li>
<li>create an empty <a href="http://doc.qt.io/qt-5/qtemporaryfile.html" target="_blank" rel="noopener noreferrer nofollow ugc">QTemporaryFile</a> with the target file-name and set it's file path to the mime-data (file-urls type)</li>
<li>fill the temporary file once it is requested in the <a href="http://doc.qt.io/qt-5/qmimedata.html#retrieveData" target="_blank" rel="noopener noreferrer nofollow ugc">QMimeData::retrieveData()</a> method (see the <a href="http://doc.qt.io/qt-4.8/qt-draganddrop-delayedencoding-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">delayed encoding example</a>)</li>
<li>the OS copies the (temp-)file to the drop-position</li>
</ol>
]]></description><link>https://forum.qt.io/post/425261</link><guid isPermaLink="true">https://forum.qt.io/post/425261</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 10 Nov 2017 08:05:38 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Thu, 09 Nov 2017 17:30:49 GMT]]></title><description><![CDATA[<p dir="auto">@JNBarchan<br />
Yes, that would be great. I think we might be able to use the wiki for it since it already has samples.</p>
]]></description><link>https://forum.qt.io/post/425147</link><guid isPermaLink="true">https://forum.qt.io/post/425147</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 09 Nov 2017 17:30:49 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Thu, 09 Nov 2017 17:27:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
There should be a "Code Snippets" forum here, and this kind of post could be put there with a decent title.</p>
]]></description><link>https://forum.qt.io/post/425146</link><guid isPermaLink="true">https://forum.qt.io/post/425146</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Nov 2017 17:27:03 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Thu, 09 Nov 2017 17:14:17 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
To drop to desktop, you must follow windows rules for the mimedata<br />
else it wont accept.</p>
<p dir="auto">This sample drags file from Qt to desktop / explorer<br />
It uses a native windows header. (#include &lt;Shlobj.h&gt;)</p>
<pre><code>#include "mainwindow.h"
#include &lt;QApplication&gt;
#include &lt;QtGui&gt;
#include &lt;Shlobj.h&gt;

class Widget : public QWidget {
  void mousePressEvent(QMouseEvent* e) {
    QPoint hotSpot = e-&gt;pos();
    QList&lt;QUrl&gt; strList;
    FILEGROUPDESCRIPTOR fgd;
    FILEDESCRIPTOR fd[ 1 ];

    strList.append( QUrl( "http://www.qt.io/" ) );
    fgd.cItems = 1;

    fgd.fgd[ 0 ].dwFlags = FD_PROGRESSUI;
    wcscpy( fgd.fgd[ 0 ].cFileName, L"qtrules.url" );
    QMimeData* mimeData = new QMimeData;
    mimeData-&gt;setText("www.gaspar.net");
    mimeData-&gt;setUrls( strList );
    mimeData-&gt;setData("text/plain", QByteArray( "http://www.gaspar.net" ) );
    mimeData-&gt;setData("text/html", QByteArray( "&lt;!--StartFragment--&gt;&lt;a href=\"http://www.gaspar.net\"&gt;The Gaspar Website&lt;/a&gt;&lt;!--EndFragment--&gt;" ) );
    mimeData-&gt;setData("FileName", QByteArray( "Gaspar Website.url" ) );
    mimeData-&gt;setData("FileGroupDescriptorW", QByteArray::fromRawData( ( const char* )&amp;fgd, sizeof ( FILEGROUPDESCRIPTOR ) ) );
    mimeData-&gt;setData("FileContents", QByteArray( "[InternetShortcut]\r\nURL=http://www.gaspar.net" ) );

    QPixmap pixmap(":/images/imagelists/16x16/webpage.png");
    render(&amp;pixmap);

    QDrag* drag = new QDrag(this);
    drag-&gt;setMimeData(mimeData);
    drag-&gt;setPixmap(pixmap);
    drag-&gt;setHotSpot(hotSpot);

    Qt::DropAction dropAction = drag-&gt;exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);

    if (dropAction == Qt::MoveAction) {
      update();
    }
  }
};

int main(int argc, char* argv[]) {
  QApplication app(argc, argv);
  Widget window;
  window.show();
  return app.exec();
}
</code></pre>
<p dir="auto">Credits goes to <a href="http://www.gaspar.net/oteqmimewindows.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.gaspar.net/oteqmimewindows.html</a></p>
<p dir="auto"><img src="https://s33.postimg.org/cj74ewy8f/drop.gif" alt="alt text" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/425138</link><guid isPermaLink="true">https://forum.qt.io/post/425138</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 09 Nov 2017 17:14:17 GMT</pubDate></item><item><title><![CDATA[Reply to Dragging out to non-Qt desktop on Thu, 09 Nov 2017 15:49:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shinsat">@<bdi>ShinSat</bdi></a><br />
your question is very unclear.</p>
<blockquote>
<p dir="auto">How and where can I handle the dropEvent outside of Qt?</p>
</blockquote>
<p dir="auto">You shouldn't and you wont handle the drop outside your application. Similar to a copy and aste via clipboard you simply provide data to the operating system and let it do the multi-window drag-handling. The final target application which receives the drop handles the data on it's own.<br />
The only result you get is when your QDrag::exec() returnes and check the returned drop result.</p>
]]></description><link>https://forum.qt.io/post/425099</link><guid isPermaLink="true">https://forum.qt.io/post/425099</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Thu, 09 Nov 2017 15:49:47 GMT</pubDate></item></channel></rss>