QSqlTableModel, data function overload
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.开发者_C百科 Where can i find it? Or is it just my call wrong?
Thanks in advance.
I'm not sure what that record.value
is supposed to be (no indication in your code of where that record
variable 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
whatever = QSqlTableModel.data(self, modelIndex, role)
精彩评论