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
|
from PyQt4 import QtGui, QtCore
import sys
class Proxii(QtGui.QSortFilterProxyModel):
def __init__(self, parent):
QtGui.QSortFilterProxyModel.__init__(self, parent)
def hasChildren(self, oModelIndex):
oSourceIndex = self.mapToSource(oModelIndex)
return self.sourceModel().hasChildren(oSourceIndex)
def canFetchMore(self, oModelIndex):
oSourceIndex = self.mapToSource(oModelIndex)
return self.sourceModel().canFetchMore(oSourceIndex)
def fetchMore(self, oModelIndex):
oSourceIndex = self.mapToSource(oModelIndex)
return self.sourceModel().fetchMore(oSourceIndex)
class testExplo(QtCore.QObject):
def __init__(self):
QtCore.QObject.__init__(self)
self.myTreeView = QtGui.QTreeView()
self.myProxy = Proxii(self.myTreeView)
self.myModel = QtGui.QFileSystemModel(self.myTreeView)
#-- Model
self.myModel.setRootPath("/home/")
#-- Proxi
self.myProxy.setSourceModel(self.myModel)
#-- treeview
self.myTreeView.setModel(self.myProxy)
rootModelIndex = self.myModel.index("/home/")
rootProxyIndex = self.myProxy.mapFromSource(rootModelIndex)
self.myTreeView.setRootIndex(rootProxyIndex)
self.myTreeView.show()
app = QtGui.QApplication(sys.argv)
myExplo = testExplo()
end = app.exec_() |
Partager