On same subject, is drag and drop from application external (files for example) suppose to work into the current application context:
- *QMainWindow * - can have the drag n drop event if *setAcceptDrops(true)*; - getting the url list here just right if enabled but it's not what is wanted in some case - *QQuickView* - *Qml DropArea* - does not seem to receive the drag n drop events - The drag and drop always is refused (under Windows with interdiction mouse cursor). Since QQuickView is not a Qwidget should the QQuickView have some sort of *setAcceptDrops(true);* equivalent? or is that unnecessary? Hope someone have some information on all this, it's highly confusing enough and example are over simplified to near useless concerning drag n drop from/to Qml versus C++ Qt one and possible interaction between the two. Thanks, Jerome On Wed, Sep 2, 2015 at 1:06 PM, Jérôme Godbout <jer...@bodycad.com> wrote: > Hi, > I'm trying to add behaviors for drag n drop on a custom QQuickItem in C++ > from Qml. > > I have use inside the C++ part: > setFlags(ItemAcceptsDrops); > into the custom QQuickItem constructor. > > I now receive event into custom handler: > dragEnterEvent(QDragEnterEvent* event) > inside the overload function. I can accept the event to begin receive : > dragMoveEvent(QDragMoveEvent* event) > > This seem to work, but the event have a null source and no data inside to > base my choice to accept or not the event. The Qml attached > QQuickDragAttached element on my object seem to have the proper information > inside it. Source is set and valid, keys are presents, supportedActions and > proposedAction are ok there. But I don't received them inside my custom > QQuickItem handler of dragEnterEvent, the QDragEnterEvent::source is null, > only the supportedActions and proposedActions are set properly. > > Here's a small example of Qml scripts > > Item > { > Rectangle > { > id: greenRect_ > x: 200 > y: 100 > width: 20; > height: 20 > color: "green" > > Drag.active: dragArea_.drag.active > Drag.hotSpot.x: width * 0.5 > Drag.hotSpot.y: height * 0.5 > Drag.proposedAction: Qt.MoveAction > //Drag.source: greenRect_ // was already set to the proper value, try to > enforce it just to make sure, not difference > Drag.keys: ["green"] > > MouseArea > { > id: dragArea_ > anchors.fill: parent > drag.target: parent > } > } > > MyCustomQQuickItem > { > x: 300 > y: 300 > width: 200 > height: 200 > } > } > > I can drag the rectangle hover my item and receive the nearly empty event. > I guess I'm missing something fundamental here but I don't known what it is. > > 1. Anybody have the mimeData map format? Drag.mimeData: { 'hasText': > true, 'text': "green" } ??? > 2. Where does the Drag.keys end up inside the C++ ? > 3. Is my drag n drop Qml part done right? > 4. What is the accept drag n drop flow to end up with > a dropEvent(QDropEvent *event) being called and handle properly. > 1. QDragEnterEvent must be Accepted > 2. QDragMoveEvent, (what to do in which case???) what happen if > accepted or not exactly??? > 3. When does the QDragLeaveEvent handler called exactly? > 4. How does one know when the drag was released (actually dropped)? > > > Thanks, > Jerome >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest