Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. implement drag and drop files and directory to qlistwidget
Forum Updated to NodeBB v4.3 + New Features

implement drag and drop files and directory to qlistwidget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjzarrin
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mjzarrin
        wrote on last edited by
        #3

        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);
            }
        }
        
        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Super.
          Please mark as solved if possible :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved