1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #===========================================================
import sys
from PyQt4 import QtGui, QtCore
class testExplo(QtCore.QObject):
def __init__(self):
QtCore.QObject.__init__(self)
self.myTreeView = QtGui.QTreeView()
self.myTreeView.keyPressEvent = self.keyPressEvent
#-- Model
self.myModel = QtGui.QFileSystemModel()
self.myModel.setReadOnly(False)
self.myModel.setRootPath(r"D:\test")
#-- treeview
self.myTreeView.setModel(self.myModel)
rootModelIndex = self.myModel.index(r"D:\test")
self.myTreeView.setRootIndex(rootModelIndex)
QtCore.QObject.connect(self.myModel,
QtCore.SIGNAL("fileRenamed ( const QString, const
QString , const QString) "),
self.printRenamed)
self.myTreeView.show()
def printRenamed(self, path, oldName, newName):
print path, oldName, newName
self.myModel.revert()
def keyPressEvent(self,event):
oModelIndex = self.myTreeView.selectedIndexes()[0]
if event.key() == QtCore.Qt.Key_Delete:
self.myModel.remove(oModelIndex)
event.accept()
QtGui.QTreeView.keyPressEvent(self.myTreeView, event)
try:
app = QtGui.QApplication(sys.argv)
myExplo = testExplo()
end = app.exec_()
except Exception, inst :
print inst
#=========================================================== |
Partager