Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>QML's <code>DragEvent</code> = <code>QQuickDropEvent</code></p> <p>This is stated in this updated version of the <a href="http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-dragevent.html" rel="nofollow">QML DragEvent documentation</a> fresh from the <a href="https://qt.gitorious.org/qt/qtdeclarative/source/751fa46df9bf06a1003df34b3e74c73c079e8626%3asrc/quick/items/qquickdroparea.cpp" rel="nofollow">sources</a></p> <pre><code>/*! \qmltype DragEvent \instantiates QQuickDropEvent \inqmlmodule QtQuick \ingroup qtquick-input-events \brief Provides information about a drag event The position of the drag event can be obtained from the \l x and \l y properties, and the \l keys property identifies the drag keys of the event \l source. The existence of specific drag types can be determined using the \l hasColor, \l hasHtml, \l hasText, and \l hasUrls properties. The list of all supplied formats can be determined using the \l formats property. Specific drag types can be obtained using the \l colorData, \l html, \l text, and \l urls properties. A string version of any available mimeType can be obtained using \l getDataAsString. */ </code></pre> <p><code>QQuickDropEvent</code>'s header is available in <a href="https://qt.gitorious.org/qt/qtdeclarative/source/751fa46df9bf06a1003df34b3e74c73c079e8626%3asrc/quick/items/qquickdroparea_p.h" rel="nofollow">src/quick/items/qquickdroparea_p.h</a>. I guess this is a private header file again, which means you are not supposed to handle these events in C++ but in Javascript.</p> <p>A <code>QQuickDropEvent</code> instance contains a private instance variable of type <code>QDropEvent</code> that you can not access directly.</p> <p><strong>Edit:</strong> You might want to copy the drop's properties in Javascript and pass an array to C++ (untested):</p> <pre><code>DropArea { var actionIdToString = function(id) { if (id === Qt.CopyAction) return 'Qt.CopyAction'; if (id === Qt.MoveAction) return 'Qt.MoveAction'; if (id === Qt.LinkAction) return 'Qt.LinkAction'; if (id === Qt.IgnoreAction) return 'Qt.IgnoreAction'; return 'Unexpected action'; } onDropped: { var dropProperties = [ drop.accepted, actionIdToString(drop.action), drop.drag.source, drop.keys, drop.supportedActions, drop.x, drop.y ] root.dropSignal(dropProperties); } } </code></pre> <p>There is a blog post about <a href="http://ruedigergad.com/2011/11/13/exchange-data-and-objects-between-c-and-qml-and-vice-versa/" rel="nofollow">passing more complex datastructures between C++ and QML</a>. As far as I can see, you will get a <code>QVariantList</code> when passing a Javascript array to your slot.</p> <p>You might want to consider using a Javascript object (<a href="http://qt-project.org/doc/qt-5.0/qtqml/qml-var.html" rel="nofollow">JSON style</a>) in order to access the drop's properties by name instead of index in C++, but I am not sure how well objects survive the step from QML to C++.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload