Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At this point in time, you will probably need to use C++, especially if you want to accept drops from outside the QML application (e.g. the user drags a file from a file manager to your app). Here's an example component class to implement a DropArea item:</p> <p>DropArea.h:</p> <pre><code>#ifndef DropArea_H #define DropArea_H #include &lt;QDeclarativeItem&gt; /** An oversimplified prototype Item which accepts any drop that includes data with mime type of text/plain, and just emits the text. */ class DropArea : public QDeclarativeItem { Q_OBJECT Q_PROPERTY(bool acceptingDrops READ isAcceptingDrops WRITE setAcceptingDrops NOTIFY acceptingDropsChanged) public: DropArea(QDeclarativeItem *parent=0); bool isAcceptingDrops() const { return m_accepting; } void setAcceptingDrops(bool accepting); signals: void textDrop(QString text); void acceptingDropsChanged(); protected: void dragEnterEvent(QGraphicsSceneDragDropEvent *event); void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); void dropEvent(QGraphicsSceneDragDropEvent *event); private: bool m_accepting; }; #endif </code></pre> <p>DropArea.cpp:</p> <pre><code>#include &lt;QGraphicsSceneDragDropEvent&gt; #include &lt;QMimeData&gt; #include "DropArea.h" DropArea::DropArea(QDeclarativeItem *parent) : QDeclarativeItem(parent), m_accepting(true) { setAcceptDrops(m_accepting); } void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event) { event-&gt;acceptProposedAction(); setCursor(Qt::DragMoveCursor); } void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) { unsetCursor(); } void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event) { emit textDrop(event-&gt;mimeData()-&gt;text()); unsetCursor(); } void DropArea::setAcceptingDrops(bool accepting) { if (accepting == m_accepting) return; m_accepting = accepting; setAcceptDrops(m_accepting); emit acceptingDropsChanged(); } </code></pre> <p>your QML:</p> <pre><code>DropArea { onTextDrop: ... } </code></pre> <p>And you can implement a DragSourceArea similarly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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