I’m trying to inherit QSqlTableModel to make data im my table display in way i need.
class TableViewModel(QSqlTableModel):
def __init__(self):
super(TableViewModel, self).__init__()
def flags(self, modelIndex):
if not modelIndex.isValid():
return
if modelIndex.column() != 1 and modelIndex.column() != 4:
return Qt.ItemIsEnabled | Qt.ItemIsSelectable
return Qt.ItemIsEditable | Qt.ItemIsEnabled | Qt.ItemIsSelectable
def data(self, modelIndex, role=Qt.DisplayRole):
if not modelIndex.isValid():
return QVariant()
if role != Qt.DisplayRole & role != Qt.EditRole:
return QVariant()
return record.value(modelIndex.column())
With this code i’m only getting empty cells. Without data() function this code work perfectly, the data displayed in TableView exactly it should be.
I’m just enmeshed by getting data from QSqlTableModel. Where can i find it? Or is it just my call wrong?
Thanks in advance.
I’m not sure what that
record.valueis supposed to be (no indication in your code of where thatrecordvariable lives or how or when it’s set). Anyway, for “getting data from QSqlTableModel” (whereby I assume you mean the base class you’re subclassing), use