Sumario
- Derivar una clase de QListWidget
- Reimplementar dragEnterEvent, dragMoveEvent y dropEvent
mylistwidget.h
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
mylistwidget.cpp
myListWidget::myListWidget(QWidget *parent) :
QListWidget(parent)
{
this->setAcceptDrops(true);
}
void myListWidget::dragEnterEvent(QDragEnterEvent *event){
if (event->mimeData()->hasUrls()){
event->acceptProposedAction();
}
}
void myListWidget::dragMoveEvent(QDragMoveEvent *event){
event->acceptProposedAction();
}
void myListWidget::dropEvent(QDropEvent *event){
if (event->mimeData()->hasUrls()){
for (int i =0; i< event->mimeData()->urls().count(); i++){
this->addItem(event->mimeData()->urls().at(i).toLocalFile());
}
}
}