Skip to content

Instantly share code, notes, and snippets.

@redstoneleo
Created November 27, 2017 13:17
Show Gist options
  • Save redstoneleo/03528b46d24335575a145ecf5a089a4f to your computer and use it in GitHub Desktop.
Save redstoneleo/03528b46d24335575a145ecf5a089a4f to your computer and use it in GitHub Desktop.
QFileSystemModel test
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyFileSystemModel(QFileSystemModel):
def __init__(self, h_align=Qt.AlignLeft, v_align=Qt.AlignLeft, parent=None):
super().__init__(parent)
self.alignments = {Qt.Horizontal: h_align, Qt.Vertical: v_align}
def headerData(self, section, orientation, role):
if role == Qt.TextAlignmentRole:
return self.alignments[orientation]
if (role == Qt.BackgroundRole):
return QBrush(QColor(0, 250, 0))
if role == Qt.DecorationRole:
return QColor(0, 250, 0) # None
else:
return QFileSystemModel.headerData(self, section, orientation, role)
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = QMainWindow()
model = QFileSystemModel()
model.setRootPath(QDir.currentPath())
model.sort(3)
table = QTableView()
#print(table.verticalHeader().defaultAlignment()) #
table.verticalHeader().setDefaultAlignment(Qt.AlignRight)
table.setModel(model)
# table.setRootIndex(model.index(QDir.currentPath()))
ui.setCentralWidget(table)
ui.resize(800, 600)
ui.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment