我有一个QSplitter:
左侧是使用QFileSystemModel显示本地系统文件的Qtreeview
右侧有QWebView和html页面,我正在逐行显示目录和文件名。
我想制作一个拖放应用程序。我已启用所有拖放所需的功能,因此它在内部工作在自己的视图上。
但是我想在这两个视图之间拖放,当我这样做时,它正确地显示加号图标,但是在删除文件时,它显示在控制台中:
QFile :: rename:空文件名或空文件名
这是我的代码:
QStringListModel *model1 = new QStringListModel();
QStringList *stringList = new QStringList();
view2->setUpdatesEnabled(true);
view2->setAcceptDrops(true);
if(oldName == "" || CPE == "") {
oldName = CPE;
} else {
oldName = oldName + " / " + CPE;
}
view2->page()->mainFrame()->addToJavaScriptWindowObject("MainWindow",newMyJavaScriptOperations);
QString mypage;
QTextStream p(&mypage);
p << "<!DOCTYPE HTML>";
p <<"<html><head>\n<link rel='stylesheet' type='text/css'";
{width:350px;height:70px;padding:10px;border:1px solid #aaaaaa;} </style>";
p << " href='webview.css' />\n";
p <<"<link href='file:///D:/QT/QT_JS/bootstrap.min.css' rel='stylesheet'>";
p << "<style type='text/css'>body { color:black }; </style>";
p<<"<script src='file:///D:/QT/QT_JS/selectCpe.js'></script>";
p << "<body ondragstart='return true'>";
p << "<ol class='breadcrumb'>";
if(CPE == NULL){
qDebug()<<"CPE1";
p << "<li class='active'>"<<cpeName<<"</li>";
}
else{
qDebug()<<"CPE2";
p << "<li><a href='javascript:void(0)' onclick = 'cpeContent()'>"<<cpeName<<"</a></li>";
p << "<li class='active'>"<<oldName<<"</li>";
}
p<<"</ol>";
</div>";
p<<"<div class='row'>";
while(tmp!= NULL)
{
if (tmp->isDir)
{
p<<"<div class='col-lg-3'>";
p<< "<a draggable='true' width='336' height='69' href='javascript:void(0)' onclick = 'openDir(this.id)' id="<< tmp->fileName<<">";
p << "<img src='file:///D:/QT/QT_JS/manilla_gnome_fs_directory.png' class='logo'><br>";
p <<"DirName: "<< tmp->fileName <<"</a></div>";
}
else
{
p<<"<div class='col-lg-3'>";
p<< "<a href='javascript:void(0)' draggable='true'>";
p << "<img src='file:///D:/QT/QT_JS/document_folder_blue.png' class='logo'><br>";
float size = tmp->size/(1024*1024);
p <<"FileName: "<< tmp->fileName <<"<br>"<<"Size: "<<size<<" MB</a></div>";
}
p<<"<br><br><br>";
tmp = (fileNode_t *)tmp->next;
}
p<<"</div>";
if(head)
{
qDebug()<<"display";
}
else
{
p <<"No Contents...";
}
model1->setStringList(*stringList);
freeFileList(head);
head = NULL;
view2->setHtml(mypage);
view2->setAcceptDrops(true);
qDebug() << "In main2 method";
view1->hide();
//tree
qDebug() << "In main3 method";
QFileSystemModel *model = new QFileSystemModel;
model->setReadOnly(false);
QString dir("c:/sample");
model->setRootPath(dir);
tree->update();
tree->repaint();
tree->resize(1100, 550);
tree->setModel(model);
tree->setRootIndex(model->index((dir)));
tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
tree->setDragEnabled(true);
tree->setTextElideMode(Qt::ElideMiddle);
tree->viewport()->setAcceptDrops(true);
tree->setAcceptDrops(true);
tree->setDropIndicatorShown(true);
tree->setDefaultDropAction(Qt::CopyAction);
tree->setDragDropMode(QAbstractItemView::DragDrop);
splitter->setAcceptDrops(true);
splitter->addWidget(tree);
splitter->addWidget(view2);
splitter->resize(1100, 550);
splitter->setWindowTitle("<- Local Files And api Files ->");
splitter->show();