I am trying to write a simple program (nothing special) which has a QListView
and some Buttons.
My question is:
How do I specifically tell the QListView
to accept Drag and Drop from the filesystem?
I currently have
setAcceptDrops(true)
Which is OK, but the drag and drop works on the whole (Main)Window. I just want it to work when the file is dragged into the QListView
.
Why doesn't this work?:
ui->listView->setAcceptDrops(true);
The whole code:
#include "player.h"
#include "ui_player.h"
#include <QListView>
Player::Player(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Player)
{
ui->setupUi(this);
setAcceptDrops(true);
//This doesnt work:
//ui->listView->setAcceptDrops(true);
}
Player::~Player()
{
delete ui;
}
void Player::dropEvent(QDropEvent *ev)
{
QList<QUrl> urls = ev -> mimeData() -> urls();
foreach(QUrl url, urls)
{
qDebug() << url.toString();
}
ev->acceptProposedAction();
}
void Player::dragEnterEvent(QDragEnterEvent *ev)
{
ev->acceptProposedAction();
}