0
votes

I drag a QStandardItem from a QListView over a QWidget. In my QWidget class I implemented dragEnterEvent and dropEvent:

void MyWidget::dragEnterEvent(QDragEnterEvent *event){
    qDebug() << "drag entering: ";
}

void MyWidget::dropEvent(QDropEvent *event){
    qDebug() << "drop received!";
}

It receives the dragEntering, but not the dropping. I have already set the acceptDrops to true in the constructor of the QWidget class. What am I missing? Thanks for help!

2
What is MyWidget?vahancho
MyWidget is just a class derived from QWidgetmep
Can be possible that the drop event is called on the parent of your widget, i mean, the list or whatever MyWidget is in?alseether
Oh, yes it is in a splitter... that could be the problemmep
Hm, setting acceptDrops of the splitter (and the mainWindow) to true didn't help. There must be something else I have to set upmep

2 Answers

2
votes

Well, I finally got the solution. I had to add event->acceptProposedAction(); in the dragEnterEvent in the widget class.

0
votes

Another cause of failure is an incorrect event type (copy and paste). Ensure they match the event handler:

dragEnterEvent(QDragEnterEvent *event)
dragMoveEvent(QDragMoveEvent *event)
dropEvent(QDropEvent *event)