* Added QWheelEvent * removed x y * Added QNativeGestureEvent * Changed wrong type of QNativeGestureEventWrap value * Added QTabletEvent * Fixing build error for QTabletEvent * adding dropaction * fix typos * Added more functions to QPainterPath * Added more functions to QPainterPath * Fixed multiple typos * Fixed multiple typos * Got QPainterPath additions working. * Modified QPainterPath to use qreal instead * Added QPointF, added a few missing methods to QPoint * Added QRectF * implemented QRectF * Added acceptDrops and setAcceptDrops to QWidget, will be useful for addon implementation of Drag and Drop * Added more methods to QUrl * Added QMimeData, additional methods to QUrl, and Dropping should now be supported * refactored * Fixed more merge conflicts * Is this my final merge conflict?? * All merge conflicts resolved * All merge conflicts resolved * Adds guide for drag and drop * lint fix Co-authored-by: Switt Kongdachalert <switt1995@yahoo.com> Co-authored-by: Atul R <atulanand94@gmail.com>
1.9 KiB
1.9 KiB
| sidebar_label | title |
|---|---|
| Drag and drop | Drag and drop |
NodeGui supports drag and drop functionality.
In order to enable a widget to accept drops you need call
widget.setAcceptDrops(true);
Following this you can then listen to few QEvents like DragEnter, DragMove, DragLeave and Drop
The complete code would look something like this:
widget.setAcceptDrops(true);
widget.addEventListener(WidgetEventTypes.DragEnter, (e) => {
let ev = new QDragMoveEvent(e);
console.log('dragEnter', ev.proposedAction());
let mimeData = ev.mimeData();
mimeData.text(); //Inspection of text works
console.log('mimeData', {
hasColor: mimeData.hasColor(),
hasHtml: mimeData.hasHtml(),
hasImage: mimeData.hasImage(),
hasText: mimeData.hasText(),
hasUrls: mimeData.hasUrls(),
html: mimeData.html(),
text: mimeData.text(),
}); //Inspection of MIME data works
let urls = mimeData.urls(); //Get QUrls
for (let url of urls) {
let str = url.toString();
console.log('url', str); //Log out Urls in the event
}
ev.accept(); //Accept the drop event, which is crucial for accepting further events
});
widget.addEventListener(WidgetEventTypes.DragMove, (e) => {
let ev = new QDragMoveEvent(e);
console.log('dragMove');
});
widget.addEventListener(WidgetEventTypes.DragLeave, (e) => {
console.log('dragLeave', e);
let ev = new QDragLeaveEvent(e);
ev.ignore(); //Ignore the event when it leaves
console.log('ignored', ev);
});
widget.addEventListener(WidgetEventTypes.Drop, (e) => {
let dropEvent = new QDropEvent(e);
let mimeData = dropEvent.mimeData();
console.log('dropped', dropEvent.type());
let urls = mimeData.urls();
for (let url of urls) {
let str = url.toString();
console.log('url', str); //Example of inspection of dropped data.
}
});