import sys
from PyQt4 import QtCore, QtGui
class MyFileProxyModel(QtGui.QFileSystemModel):
def __init__(self):
super(MyFileProxyModel, self).__init__(None)
self.headers=['1','2','3','4']
def headerData(self, column, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.
QVariant(self.
headers[column
])
def __init__(self):
super(MyProxyFilter, self).__init__(None)
def filterAcceptsRow(self, sourceRow, sourceParent):
return True
def __init__(self):
super(MyMainWindow, self).__init__(None)
tableView.setSortingEnabled(True)
vl.addWidget(tableView)
self.setLayout(vl)
fileModel = MyFileProxyModel()
rootModelIndex
= fileModel.
setRootPath(QtCore.
QDir.
currentPath())
proxyFilter = MyProxyFilter()
proxyFilter.setSourceModel(fileModel)
tableView.setModel(proxyFilter)
tableView.setRootIndex(proxyFilter.mapFromSource(rootModelIndex))
if __name__ == '__main__':
win = MyMainWindow()
win.show()
app.exec_()
sys.exit()
import sys
from PyQt4 import QtCore, QtGui
class MyFileProxyModel(QtGui.QFileSystemModel):
def __init__(self):
super(MyFileProxyModel, self).__init__(None)
self.headers=['1','2','3','4']
def headerData(self, column, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
return QtCore.QVariant(self.headers[column])
return QtCore.QVariant()
class MyProxyFilter(QtGui.QSortFilterProxyModel):
def __init__(self):
super(MyProxyFilter, self).__init__(None)
def filterAcceptsRow(self, sourceRow, sourceParent):
return True
class MyMainWindow(QtGui.QWidget):
def __init__(self):
super(MyMainWindow, self).__init__(None)
vl = QtGui.QVBoxLayout()
tableView = QtGui.QTableView()
tableView.setSortingEnabled(True)
vl.addWidget(tableView)
self.setLayout(vl)
fileModel = MyFileProxyModel()
rootModelIndex = fileModel.setRootPath(QtCore.QDir.currentPath())
proxyFilter = MyProxyFilter()
proxyFilter.setSourceModel(fileModel)
tableView.setModel(proxyFilter)
tableView.setRootIndex(proxyFilter.mapFromSource(rootModelIndex))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
win = MyMainWindow()
win.show()
app.exec_()
sys.exit()
To copy to clipboard, switch view to plain text mode
Bookmarks