def saveTableModelAsCsv(model: QAbstractTableModel, path: str): """ Saves table model on given path as csv. Takes just horizontal header. :param model: Model you want to save. :type model: QAbstractTableModel :param path: Path where model should be saved. :type path: str """ with open(path, 'w') as f: writer = csv.writer(f) # header writer.writerow([ model.headerData(i, Qt.Horizontal, Qt.DisplayRole) for i in range(model.columnCount()) ]) for row in range(model.rowCount()): writer.writerow([ model.data(model.index(row, column), Qt.DisplayRole) for column in range(model.columnCount()) ])
def headerData(self, section, orientation, role=Qt.DisplayRole): if orientation == Qt.Horizontal and role == Qt.DisplayRole: return self.header[section] return QAbstractTableModel.headerData(self, section, orientation, role)
def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.DisplayRole and orientation == Qt.Horizontal: return self.header_labels[section] return QAbstractTableModel.headerData(self, section, orientation, role)
def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.DisplayRole and orientation == Qt.Horizontal: return Account.data_field_names[section] return QAbstractTableModel.headerData(self, section, orientation, role)
def headerData(self, section, orientation, role=Qt.DisplayRole): if orientation == Qt.Horizontal and role == Qt.DisplayRole: return translate( self.columns_names[section] ) #('Font family') if section == 0 else ('Embedded') return QAbstractTableModel.headerData(self, section, orientation, role)