python - PyQt : Editable QFileSystemModel in a QTreeView

标签 python pyqt pyqt4 qfilesystemmodel

我的文件系统上有这个:

 - myFolder
      - mySubFolder
  1. 在 TreeView 中,我展开文件夹 “myFolder”
  2. 然后我将其重命名为“myFolder_2”
  3. 最后,我尝试将文件夹 “mySubFolder” 重命名为 “mySubFolder_2”

“mySubFolder_2” 不再被视为文件夹,而是大小为 -1 字节的未知文件夹,我收到消息:QFileSystemWatcher:添加路径失败:< strong>我的文件夹

这是我的源代码:

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_()

欢迎任何帮助。

最佳答案

在 TreeView 上设置之前,您需要在模型上设置根路径:

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
treeView = QtGui.QTreeView()
fileSystemModel = QtGui.QFileSystemModel(treeView)
fileSystemModel.setReadOnly(False)
root = fileSystemModel.setRootPath('.')
treeView.setModel(fileSystemModel)
treeView.setRootIndex(root)
treeView.show()
app.exec_()

关于python - PyQt : Editable QFileSystemModel in a QTreeView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8914495/

相关文章:

使用Rascal分析和转换python源文件

python - 异步 Pool.execute 与 Connection.execute

python - 调用 setParent 时 QMenu 显示不正确

python - 平均值和最大值之间差距较大的列表的 Pyqt 步长

python - QGIS 渲染 shapefile 时如何让 Python 等待

python - 使用 pyqt 检索 postgres 中的一行中的所有记录

python - 如何让子类使用父类的默认值?

python - 关于事件的使用

python - QSystemTrayIcon 在 Ubuntu 12.04 中不显示

python - Pyinstaller - ImportError : No system module 'pywintypes' (pywintypes27. dll)