Home > other >  PyQt5 TreeView drag and drop
PyQt5 TreeView drag and drop

Time:09-25

I want to make a PyQt5 GUI software, which involves to the operation of the directory tree, I want it to be able to drag and drop within a directory tree, to change the location of the document. I use the QTreeView and QFileSystemModel realize this function, but found it can't drag and drop.
Code:
 
The class FileTreeView (QTreeView) :
Def __init__ (self, parent=None) :
Super () __init__ (parent)
Self. SetDragEnabled (True)
Self. SetAcceptDrops (True)
Self. SetDragDropMode (QAbstractItemView. DragDrop)
Self. SetDefaultDropAction (Qt. CopyAction)

And then use this class behind:
 
The self. The UI. File_view=FileTreeView (self. UI. LayoutWidget)
The self. The UI. File_view. SetObjectName (" file_view ")
The self. The UI. The verticalLayout. AddWidget (self. UI. File_view)

And then set the model:
 
The self. The model=QFileSystemModel (self)
The self. The UI. File_view. SetModel (self. Model)

But found to drag and drop.
Because can't screenshots when drag and drop, so can't let you see the effect of failure, as a general description is a red symbol is prohibited.
Does anyone know why?

CodePudding user response:

Does anyone know? Urgent, etc!

CodePudding user response:

Does anyone know? Urgent, etc!
  • Related