我是Python的新手,它试图构建一个UI在Maya的两个位置之间复制文件,这是在两个文件夹结构列表之间的简单拖放。我尝试从网上复制示例代码以使其起作用,但是除了显示UI之外,它无法做任何事情。
from PySide2 import QtWidgets, QtCore
class dirTreeView(QtWidgets.QTreeView):
def __init__(self, parent=None):
super(dirTreeView, self).__init__(parent)
self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.setDragDropMode(QtWidgets.QAbstractItemView.DragDrop)
self.setDropIndicatorShown(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(QtCore.Qt.CopyAction)
event.proposedAction()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.emit(QtCore.SIGNAL("accepted()"), links)
else:
event.ignore()
window = QtWidgets.QWidget()
layout = QtWidgets.QGridLayout()
srcDataModel = QtWidgets.QFileSystemModel()
srcDataModel.setRootPath(QtCore.QDir.currentPath())#will have src path
srcModel = dirTreeView()
srcModel.setModel(srcDataModel)
srcDataModel.setRootPath(QtCore.QDir.currentPath())#will have des path
desModel = dirTreeView()
desModel.setModel(srcDataModel)
layout.addWidget(srcModel, 0, 0)
layout.addWidget(desModel, 0, 1)
window.setLayout(layout)
window.show()
只需要通过拖放操作在两个位置之间复制文件,