2

I've got this on my file System :

 - myFolder
      - mySubFolder
  1. Within the TreeView I expand the folder "myFolder".
  2. Then I rename it as "myFolder_2".
  3. 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.

BЈовић
  • 62,405
  • 41
  • 173
  • 273
J.D.
  • 45
  • 1
  • 6

1 Answers1

0

You need to set the root path on the model before setting it on the 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_()
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
  • Thank you for your quick reply but the problem is still the same. – J.D. Jan 18 '12 at 20:36
  • @JeanDalmayrac. Works fine for me on Linux. Must be a Windows issue - a bug in Qt maybe? – ekhumoro Jan 18 '12 at 20:47
  • I've got the same issue under Windows and Unix with python 2.6 and PyQt4.5.2. – J.D. Jan 18 '12 at 20:54
  • Another problem is that if I expand the 2 folders and then I edit the first one, I have a message box saying that the name I have entered can not be used. – J.D. Jan 18 '12 at 21:00
  • 1
    @JeanDalmayrac. After some more testing on Linux (Python 2.7.2, Qt 4.8.0, PyTt 4.9), the problem seems to come and go. There is obviously some updating issue with the internal `QFileSystemWatcher` that the model uses. (NB: A little googling reveals `QFileSystemWatcher` is pretty flaky and is slated for removal in Qt 5). – ekhumoro Jan 18 '12 at 21:10