battersea
12th November 2010, 16:20
Hi,
I have an application consisting of a simple QLabel:
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:
void dragEnterEvent(QDragEnterEvent* event) {
std::cout << "MyLabel::dragEnterEvent()::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyLabel::dragEnterEvent()::end" << std::endl;
}
void dropEvent(QDropEvent* event) {
std::cout << "MyLabel::dropEvent()::begin" << std::endl;
std::cout << "MyLabel::dropEvent()::end" << std::endl;
}
};
and a QListView:
class MyListView : public QListView {
Q_OBJECT
public:
MyListView(QWidget * parent = 0) : QListView(parent) {
setAcceptDrops(true);
setDropIndicatorShown(true);
};
virtual ~MyListView() {};
private:
void dragEnterEvent(QDragEnterEvent* event) {
std::cout << "MyListView::dragEnterEvent::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyListView::dragEnterEvent::end" << std::endl;
}
void dropEvent(QDropEvent* event) {
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
I have an application consisting of a simple QLabel:
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:
void dragEnterEvent(QDragEnterEvent* event) {
std::cout << "MyLabel::dragEnterEvent()::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyLabel::dragEnterEvent()::end" << std::endl;
}
void dropEvent(QDropEvent* event) {
std::cout << "MyLabel::dropEvent()::begin" << std::endl;
std::cout << "MyLabel::dropEvent()::end" << std::endl;
}
};
and a QListView:
class MyListView : public QListView {
Q_OBJECT
public:
MyListView(QWidget * parent = 0) : QListView(parent) {
setAcceptDrops(true);
setDropIndicatorShown(true);
};
virtual ~MyListView() {};
private:
void dragEnterEvent(QDragEnterEvent* event) {
std::cout << "MyListView::dragEnterEvent::begin" << std::endl;
event->acceptProposedAction();
std::cout << "MyListView::dragEnterEvent::end" << std::endl;
}
void dropEvent(QDropEvent* event) {
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