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. Drag&Drop
Qt 6.11 is out! See what's new in the release blog

Drag&Drop

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.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.
  • K Offline
    K Offline
    Kn1fe
    wrote on last edited by
    #1

    I have custom QTableWidget, how drop lines from table to file system? File to program workd perfect

    void ArchiveQTableWidget::dragEnterEvent(QDragEnterEvent *event)
    {
        if (event->mimeData()->hasUrls()) {
            event->acceptProposedAction();
        }
    }
    
    void ArchiveQTableWidget::dragMoveEvent(QDragMoveEvent *event)
    {
        event->acceptProposedAction();
    }
    
    void ArchiveQTableWidget::dragLeaveEvent(QDragLeaveEvent *event)
    {
        event->accept();
    }
    
    void ArchiveQTableWidget::dropEvent(QDropEvent *event)
    {
        foreach (const QUrl &url, event->mimeData()->urls()) {
            QString fileName = url.toLocalFile();
            qDebug() << "Dropped file:" << fileName;
        }
    }
    
    void ArchiveQTableWidget::startDrag(Qt::DropActions supportedActions)
    {
        qDebug() << supportedActions;
        QFile qf("1.txt");
        qf.open(QFile::WriteOnly);
        qf.write(QByteArray("dasdasdwqdd"));
        qf.close();
        QMimeData *mimeData = new QMimeData;
        mimeData->setUrls(QList<QUrl>() << QUrl(QFileInfo("1.txt").absoluteFilePath()));
        QDrag *drag = new QDrag(this);
        drag->setMimeData(mimeData);
        drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Looks a bit like this stack overflow question.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kn1fe
        wrote on last edited by
        #3

        I found solution for one file, how copy more that one file?

                QString filename = "1.txt";
                QMimeData* mimeData = new QMimeData;
                FILEGROUPDESCRIPTOR desc;
                desc.cItems = 1;
                desc.fgd[0].dwFlags = FD_PROGRESSUI;
                wcscpy_s(desc.fgd[0].cFileName, filename.toStdWString().c_str());
                // make a deep copy here
                mimeData->setData("FileGroupDescriptorW", QByteArray((const char*)&desc, sizeof(FILEGROUPDESCRIPTOR)));
                mimeData->setData("FileContents", QByteArray("whatadjsaofhniewfnj"));
                QDrag *drag = new QDrag(this);
                drag->setMimeData(mimeData);
                drag->exec(Qt::CopyAction | Qt::MoveAction);
        
        1 Reply Last reply
        1

        • Login

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