void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); ui->lineEdit->setAcceptDrops(false); this->setAcceptDrops(true); // 拖拽处理函数 void MainWindow::dragEnterEvent(QDragEnterEvent *event) { #if 1 // 判断拖拽文件类型,文件名 接收该动作 if (event->mimeData()->hasFormat("text/uri-list")) { event->acceptProposedAction(); } #endif } // 拖拽释放处理函数 void MainWindow::dropEvent(QDropEvent *event) { #if 1 QList<QUrl> urls = event->mimeData()->urls(); if (urls.isEmpty()) { return; } QString fileName = urls.first().toLocalFile(); if (fileName.isEmpty()) { return; } ui->lineEdit->setText(fileName); #endif }
http://blog.csdn.net/emdfans/article/details/45672679
时间: 2024-12-10 03:20:20