PDA

View Full Version : Drag into a QDeclarativeView



frankiefrank
2nd October 2011, 14:47
I have a QDeclarativeView to display my QML. I want to implement an interaction with my existing widgets, mainly to drag an item from a QTreeView and drop it onto the QDeclarativeView - I want to catch just the drop action and then based on the mime data decide what to do in my QML.

Currently I tried to setAcceptDrops(true) on my QDeclarativeView but still, when I try to drag an item on top of it I have the mouse cursor saying no drop is allowed.

I couldn't find an example for this online. Can anyone help out?



// header
QDeclarativeView *mView;
QDeclarativeEngine *mEngine;
QDeclarativeContext *mContext;

// cpp
mView = new QDeclarativeView(this);
mEngine = mView->engine();
mContext = mEngine->rootContext();
mView->setAcceptDrops(true);

frankiefrank
3rd October 2011, 13:12
Solution: as presented by mbrasser from the Qt Nokia Developer forums:



The qmlviewer application implements drag-and-drop for the view; if you’d like to refer to the source it is implemented in tools/qml/qmlruntime.cpp.


I used the implementation from there and seems like it's working.