我有自定义QTableWidget,我如何将Drag& Drop从表索引转移到文件夹?我有QList集合和档案文件 此代码非常适合删除应用程序
void ArchiveQTableWidget::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return && currentRow() > -1)
enterClicked(currentIndex());
QTableWidget::keyPressEvent(event);
}
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)
{
StreamQMimeData mimeData = new StreamQMimeData;
connect(mimeData, SIGNAL(dataRequested(QString)),
this, SLOT(createData(QString)), Qt::DirectConnection);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
}
答案 0 :(得分:1)
您需要致电QMimeData::setUrls( QList<QUrl> )
。