QML DropArea accept external drag
-
I've noticed a new DropArea component in Qt5. I'm trying to drag a file from Finder (Mac) but only onEntered method is called. The drag.source property is also null.
@import QtQuick 2.0Rectangle {
id: background;
color: "white";
width: 300;
height: 300;DropArea { id: dropArea; anchors.fill: parent; onEntered: { background.color = "gray"; drag.accept (Qt.CopyAction); console.log("onEntered"); } onDropped: { console.log ("onDropped"); } onExited: { bckground.color = "white"; console.log ("onExited"); } }
}@
Am I missing something?
-
That is odd, your code works fine on my machine - that's Qt5 from git, using Linux. I dropped a file from the Dolphin filemanager onto the app and onDropped was called as expected.
drag.source is Null in my case as well, so this does not seem to be a problem.Are you using the official Qt5 beta release?
Did you try dropping something else, like a text-snipped or anything from another source other than finder? -
Yes, I'm using oficial Qt5 beta build from here:
http://releases.qt-project.org/qt5.0/beta1/qt-mac-opensource-5.0.0-beta1-offline.dmgDragging some code from Qt Creator doesn't work as well, unfortunately.
so this does not seem to be a problem.
Did you mean "does seem to be a problem"? -
so this does not seem to be a problem.
Did you mean “does seem to be a problem”?Rephrasing: The fact that drag.source=Null does not seem to be a problem, i.e. unrelated to your problem, since it is Null in my case as well, still onDropped gets executed on my machine.
I'm afraid I can't help you here. My guess is that this is a MacOS-specific problem. My git-clone's qtbase module is at v5.0.0-beta1 and the qtdeclarative (where the code for DropArea lies) module is ahead of v5.0.0-beta1 by four non-DnD-related commits - so the beta vs git-clone does not seem to be an issue.
Just for the fun of it, can you check whether DnD in general (i.e. good old Widgets, no QtQuick) works with the following code?
@
/* test.pro:
TEMPLATE=appTARGET=test
QT += gui widgets
SOURCES+=test.cpp
*/#include <QApplication>
#include <QWidget>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDebug>class Widget:public QWidget{
public:
Widget():QWidget(){
setAcceptDrops(true);
}
protected:
void dragEnterEvent(QDragEnterEvent* e){
qDebug()<<"dragEnter";
e->accept();
}
void dropEvent(QDropEvent* e){
qDebug()<<"dropEvent";
e->accept();
}
};int main(int argc, char* argv[])
{
QApplication app(argc,argv);Widget w; w.show(); return app.exec();
}
@The behaviour of this code is the same as in your QML-code. Again: works fine on my machine, could be of use to know whether this fails on MacOS.
-