QListView not accepting external drops
Hi,
I have an application consisting of a simple QLabel:
Code:
class MyLabel
: public QLabel {Q_OBJECT
public:
MyLabel
(QWidget * parent
= 0, Qt
::WindowFlags f
= 0) : QLabel(parent,f
) { setAcceptDrops(true);
setDropIndicatorShown(true);
};
virtual ~MyLabel() {};
private:
std::cout << "MyLabel::dragEnterEvent()::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyLabel::dragEnterEvent()::end" << std::endl;
}
std::cout << "MyLabel::dropEvent()::begin" << std::endl;
std::cout << "MyLabel::dropEvent()::end" << std::endl;
}
};
and a QListView:
Code:
Q_OBJECT
public:
setAcceptDrops(true);
setDropIndicatorShown(true);
};
virtual ~MyListView() {};
private:
std::cout << "MyListView::dragEnterEvent::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyListView::dragEnterEvent::end" << std::endl;
}
std::cout << "MyListView::dropEvent::begin" << std::endl;
std::cout << "MyListView::dropEvent::end" << std::endl;
}
};
The QLabel widget accepts drops from files outside the Qt application, resulting in the output:
MyLabel::dragEnterEvent::begin
MyLabel::dragEnterEvent::end
MyLabel::dropEvent::begin
MyLabel::dropEvent::end
The QListview widget does not accept drops from files outside the Qt application, resulting in the output:
MyListView::dragEnterEvent::begin
MyListView::dragEnterEvent::end
So even though the proposed action is accepted in MyListView::dragEnterEvent, the MyListView::dropEvent function is never called...
So my question is the following:
What's keeping the QListView from calling the dropEvent?
Eventually, I will want to add the file names of the dropped files into the list, but without the dropEvent ever being called, I don't see how I can do this...
Cheers,
Ben
Re: QListView not accepting external drops (FIXED)
Code:
event->acceptProposedAction();
}
seems to fix the issue.
The parent "dragMoveEvent" was ignoring the event. See also this thread: http://www.qtcentre.org/threads/3498...and-QTableView