PyQt:QTreeView 中可编辑的 QFileSystemModel
我的文件系统上有这个:
- myFolder
- mySubFolder
- 在 TreeView 中,我展开文件夹“myFolder”。
- 然后我将其重命名为“myFolder_2”。
- 最后,我尝试将文件夹“mySubFolder”重命名为“mySubFolder_2”。
“mySubFolder_2” 不再被视为文件夹,而是被视为大小为 -1 字节的未知文件夹,并且我收到消息:QFileSystemWatcher:无法添加路径:myFolder 。
这是我的源代码:
from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
treeView = QtGui.QTreeView()
fileSystemModel = QtGui.QFileSystemModel(treeView)
fileSystemModel.setReadOnly(False)
treeView.setModel(fileSystemModel)
folder = "."
treeView.setRootIndex(fileSystemModel.setRootPath(folder))
treeView.show()
end = app.exec_()
欢迎任何帮助。
I've got this on my file System :
- myFolder
- mySubFolder
- Within the TreeView I expand the folder "myFolder".
- Then I rename it as "myFolder_2".
- And finaly I try to rename the folder "mySubFolder" as "mySubFolder_2".
"mySubFolder_2" in is no more considered as a folder but as unknown with a size of -1 bytes and I've got the message : QFileSystemWatcher: failed to add paths: myFolder.
Here is the my source code :
from PyQt4 import QtGui
import sys
app = QtGui.QApplication(sys.argv)
treeView = QtGui.QTreeView()
fileSystemModel = QtGui.QFileSystemModel(treeView)
fileSystemModel.setReadOnly(False)
treeView.setModel(fileSystemModel)
folder = "."
treeView.setRootIndex(fileSystemModel.setRootPath(folder))
treeView.show()
end = app.exec_()
Any help will be welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在树视图上设置之前,您需要在模型上设置根路径:
You need to set the root path on the model before setting it on the treeview: