Drop files to the mainWindow (QDeclarativeView)
-
You did not add an eventFilter on the viewport right?
have a look at QObject::installEventFilteradditionally, what I normally do is setting setAcceptDrops on the main window and implements the drag/drop events also there.
-
can you send me your example code , please
-
No I can't, my code is closed source for my boss, sorry.
But you can have a look at this wiki page: "Drag and Drop of files":http://developer.qt.nokia.com/wiki/Drag_and_Drop_of_files
-
Really thanks, Gerolf.
but the key of my question is QDeclarativeView
I use QML , so my Window is Inherited from QDeclarativeView , below is the Inherrited tree :
MyView <---------- I work here
┗QmlApplicationViewer <-----------Qt Creator wizard generated
┗QDeclarativeView <----------- must inherited form this class, because use QML
┗QGraphicsView
┗QAbstractScrollArea
┗QFrame
┗QWidget <-------- if I inherited from QWidget direct , drop OK!
┗QObjectWhy?
-
That's not 100% correct
@
MyView <————— I work here
┗QmlApplicationViewer <—————-Qt Creator wizard generated
┗QDeclarativeView <—————- must inherited form this class, because use QML
┗QGraphicsView
┗QAbstractScrollArea
┗QFrame
┗QWidget <———— if I inherited from QWidget direct , drop OK!
┗QObject
┗> content QWidget as viewport <-- here the drop events will come to!!
@if MyView is your main window then set drops on viewport and myView and use an event filter on the view port of the scroll area, which will receive the drop events.
-
I tried installEventFilter , my code here
@
MyView::MyView(QWidget *parent)
: QmlApplicationViewer(parent)
{setAcceptDrops(true); this->viewport()->setAcceptDrops(true); this->viewport()->installEventFilter(this);
}
bool MyView::eventFilter(QObject *obj, QEvent *event)
{
if (obj == this->viewport() ) {
if (event->type() == QEvent::DragEnter) {
QDragEnterEvent enterEvent = static_cast<QDragEnterEvent>(event);
qDebug() << "enter" ;
enterEvent->accept();return true; } else { return false; } } else { return QmlApplicationViewer::eventFilter(obj, event); }
}
@I understand this Method can intercept all the event . Thus Catch the DragEnter event.
but my Problem is not catch event . first posted code Already can catch DragEnter event, but MyView not accept drag, Mouse display a forbidden cursor .
when used installEventFilter , the problem Still......................
-
[quote author="hoozi" date="1311771920"]but my Problem is not catch event . first posted code Already can catch DragEnter event, but MyView not accept drag, Mouse display a forbidden cursor.
[/quote]Ah, no we come closer to the problem.
You have to accept the drag/drop operation in dragEnter:@
void DocumentWindow::dragEnterEvent(QDragEnterEvent* event)
{
// if some actions should not be usable, like move, this code must be adopted
event->acceptProposedAction();
}
@ -
problem Still ......
-
I feel so sorry for you. :-(
-
Hi, I looked a bit into this and also on the internet. Seems like in QDeclarativeView, dropping from outside does not work anymore, "see this thread":http://developer.qt.nokia.com/forums/viewthread/913
You can have a look at "this code fragements,":http://bytebucket.org/gregschlom/qml-drag-drop/src/0d430d66ceb6 perhaps they help you
-
Thanks, Gerolf
I run Grégory Schlomoff 's code , it works . but a few problemhe Packaged the code to Plugin, I don't understand his code.
I email he.Anyway, Thank you for pay lots of time for me.