I'm struggling with an issue that QEvent::Drop
event is never generated for my QQuickView
window.
I need to implement a drag'n'drop functionality, to drop files from explorer to the QQuickView
.
As described in this post, i've istalled an eventfilter for the QQuickView
objet, and in eventFilter()
method trying to catch required events. The QEvent::DragMove
is being generated as expected, as i drag a file over the view. But when i drop the file on the view, the QEvent::Drop
is not being generated. Instead, the QEvent::DragLeave
is generated.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
Filter f;
QQuickView *view = new QQuickView;
view->installEventFilter(&f);
view->show();
return a.exec();
}
And here is a (Event)Filter class code: (header)
class Filter : public QObject
{
Q_OBJECT
public:
Filter(){};
virtual bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
};
(source)
bool Filter::eventFilter(QObject *watched, QEvent *event)
{
if(event->type() == QEvent::DragMove)
qDebug() << "it's a drag";
if(event->type() == QEvent::Drop)
qDebug() << "it's a drop"; // <<-- Never reaches here
return QObject::eventFilter(watched, event);
}
My colleagues helped me out with this question.
Apparently you have to add a DropArea
item to your QML
root file, and after that the QQuickView
will start receiving QEvent::Drop
events.
I can not find any documentation on this case though, and i also wonder what would be more general solution for this, if you had a QWindow
class instead.
Anyway, I'm closing this question.