Solved implement drag and drop files and directory to qlistwidget
-
Hello My Friends
I have a GUI qt application with a QListWidget. i need to add file and directory path to QListWidget after drag and drop inside it.
I'm newbie in QT. I'll be appreciated if anyone give me a simple way to do this.
thank you very much. -
hi
This shows for mainwindow but is the same for any widget
http://stackoverflow.com/questions/14895302/qt-drag-drop-add-support-for-dragging-files-to-the-applications-main-window -
thank you very much @mrjj
It is the very easy solution. thanks
its my code in MainWindow#include <QMimeData> #include <QDragEnterEvent> void MainWindow::dragEnterEvent(QDragEnterEvent *e) { if (e->mimeData()->hasUrls()) { e->acceptProposedAction(); } } void MainWindow::dropEvent(QDropEvent *e) { foreach (const QUrl &url, e->mimeData()->urls()) { QString fileName = url.toLocalFile(); ui->listWidget->addItem(fileName); } }
-
Super.
Please mark as solved if possible :)